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