Java --------------- String basic interview questions

Source: Internet
Author: User

Java --------------- String basic interview questions

Package stu. love. a;/* String: */public class StringDemo {public static void main (String [] args) {// the String is a constant. Once a String is created, the String ss = "hello"; ss = "world"; System. out. println (ss); // special case:/* when defining s2, go to the constant pool to check whether the string "1000phone" exists. If the constant pool already exists, do not create it, otherwise, when defining s3, check whether the constant pool has the String "1000phone". If the result exists, */String s2 = "1000 phone" is no longer created "; string s3 = "1000 phone"; System. out. println (s2 = s3); // trueString s4 = new String ("1000 phone"); System. out. println (s2 = s4); // false // String overwrites the boolean equals (Object obj) method in the Object to determine whether the content of the two strings is the same as that of System. out. println (s2.equals (s4); // interview question: several objects are created in the following two sentences: String s5 = "1000 phone "; // The object is the String "1000 phone" String s6 = new String ("1000 phone"); // If the constant pool contains "1000 phone", there is only one object, this object is new String () // If the constant pool does not contain "1000 phone", there are two objects, the two are new String () and "1000 phone "}}


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.