Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings. Because String objects are immutable they can be shared. For example: Strings是常量;一旦创建,它的值就不可被改变。因为String是不可变对象,所以能被共享。
String str = "abc";
is equivalent to: 相当于:
char data[] = {'a', 'b', 'c'};
String str = new String(data);
解释: String s = "ABC"; s.toLowerCase(); toLowerCase()方法不会改变s中包含的数据“ABC”。而是创建一个新的String对象并将其初始化为“abc”,然后返回这个新对象的引用。