toUpperCase in Java does not work [duplicate]

The code

String c = "IceCream";
String upper = c.toUpperCase();
System.out.println(upper);

correctly prints “ICECREAM”. However, the original string c isn’t changed. Strings in Java are immutable so all operations on the string return a new copy.

Leave a Comment