Java Basics-string and StringBuffer

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.