Hi,
I am Harikrishan.
please any one tell me.
string is immutable in java why?
i know string is immutable in java and meaning of immutable.
but why string is immutable in java.
please help me.
Printable View
Hi,
I am Harikrishan.
please any one tell me.
string is immutable in java why?
i know string is immutable in java and meaning of immutable.
but why string is immutable in java.
please help me.
For one thing: a String couldn't serve as a key in a Map<String, ?> nor can substrings share their char buffers.
kind regards,
Jos
Also, how would using String literals make sense? What happens if you do this?
Code:System.out.println("cats"); //prints cats, okay
"cats".add(" and more cats"); //since Strings are mutable, this appends the String?
System.out.println("cats"); //this now prints out something other than the literal?