String and StringBuffer in java difference of

String

  • String class object is immutable once created .
  • String object unmodifiable Unicode encoding strings.
  • Java double quotes is also used as a String object string.

E.g:

System.out.println("abc".length()); // 输出3

StringBuffer

  • Content StringBuffer object can be changed .
  • If you frequently modify the content of the string, use the StringBuffer.
  • If you often String object string modify the content, it would lead to that is time-consuming and space consuming.
  • Numerous modifications StringBuffer class has strings.

Create a StringBuffer string object:

StringBuffer stringBuffer = new StringBuffer("abc");
stringBuffer.append("d"); // 字符串末尾附加d
System.out.println(stringBuffer); // 输出:abcd
Published 44 original articles · won praise 8 · views 2468

Guess you like

Origin blog.csdn.net/qq_39659278/article/details/100006989