Java record -25-string class depth profiling

Source: Internet
Author: User

Deep anatomy of the String class in Java

Definition of String class in 1.Java source code:

Public final class String extends Object implements Serializable, Comparable<string>, charsequence

2.Stringclass represents a string. All string literals (such as) in a Java program "abc" are implemented as instances of this class.

3. Strings are constants, and their values cannot be changed after they are created. A string buffer supports variable strings. Because the String object is immutable, it can be shared. For example: String str = "ABC";

Equivalent to: char data[] = {' A ', ' B ', ' C '}; String str = new string (data);

4. String The class includes methods that can be used to examine a single character of a sequence, compare strings, search strings, extract substrings, create a copy of a string, and convert all characters to uppercase or lowercase. Case mappings are based on Character the Unicode standard version specified by the class.

The 5.Java language provides special support for string concatenation symbols ("+") and for converting other objects to strings. string concatenation is StringBuilder implemented through the (or StringBuffer ) class and its append methods. String conversions are implemented by methods that are toString defined by the Object class and can be inherited by all classes in Java.

6. String ss1 = "Hello";
String SS2 = "World";
String SS3 = ss1 + ss2;
System.out.println (SS3);

Since strings are constants, they cannot be changed once they are created. SS3 and SS1, SS2 are three different objects, SS3 is a newly generated object, not SS1 and SS2 stitching. So when using the + stitching string, a new object is generated instead of adding content to the original string object.


Java record -25-string class depth profiling

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.