java initialise a string with value code example Example: how to initialize a string in java Scanner sc = new Scanner(System.in); String str = sc.next();