Java record-25-String in-depth analysis

Source: Internet
Author: User

Java record-25-String in-depth analysis
In-depth analysis of the String class in Java 1. Definition of the String class in Java source code: public final class String extends Object implements Serializable, Comparable <String>, CharSequence2.String class represents the String. All character strings (such as "abc") in Java programs are implemented as such instances. 3. strings are constants. Their values cannot be changed after creation. The string buffer supports variable strings. Because the String object is unchangeable, it can be shared. For example: String str = "abc"; equivalent to: char data [] = {'A', 'B', 'C'}; String str = new String (data ); 4. the String class can be used to check a single character, compare String, search String, extract substring, create a copy of String, and convert all characters to uppercase or lowercase letters. The case-sensitive ing is based on the Unicode Standard Edition specified by the Character class. 5. the Java language provides special support for String concatenation symbols ("+") and conversion of other objects into strings. String concatenation is implemented through the StringBuilder (or StringBuffer) class and its append method. String Conversion is implemented using the toString method. This method is 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 the string is a constant, it cannot be changed once created. Ss3, ss1, and ss2 are three different objects. ss3 is a new object, not merged by ss1 and ss2. Therefore, when you use + to splice strings, a new object is generated instead of adding content to the original String object.

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.