Can one create a method which gets a String and modifies it?

Q

Can one create a method which gets a String and modifies it?

✍: Guest

A

No. In Java, Strings are constant or immutable; their values cannot be changed after they are created, but they can be shared. Once you change a string, you actually create a new object. For example:
String s = "abc"; //create a new String object representing "abc"
s = s.toUpperCase(); //create another object representing "ABC"

2012-08-24, 2149👍, 0💬