Difference:
(1) The String class object is an immutable object, once you modify the value of the string object, implicitly re-create a new object, release the original string object, the StringBuffer class object is a modifiable object, you can modify the value by the Append () method
(2) The performance of a string class object is far less than the StringBuffer class.
String S=new "Hallo"; two objects created, string in constant pool, s pointing to String string object, stringstring object pointing to strings in constant pool
Small example:
String str= "ZXCVBNM";
System.out.println (Str.length ());
System.out.println (Str.touppercase ());
System.out.println (Str.substring (3, 6));
System.out.println (Str.trim (). Equalsignorecase ("zxcvbnm"));
System.out.println (Str.indexof ("C"));
System.out.println (Str.substring (3));
System.out.println (Str.trim ());
Char[] Ch=str.tochararray ();
for (char c:ch) {
System.out.println (c);
}
Java Basics-string and StringBuffer