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