Java Basics Interview Question: How to convert a comma-separated string into an array? String s = "a" + "B" + "C" + "D"; Generate several objects?

Source: Internet
Author: User

 PackageCom.swift; Public classDouhao_string_test { Public Static voidMain (string[] args) {/** How to convert a comma-separated string into an array?         * String s = "a" + "B" + "C" + "D"; Generate several objects? */String str= "sdjkfl,sldfj,abc,ei3,239d"; String[] Arr=str.split (",");  for(String S:arr) {System.out.println (s); } String S1=NewString ("Hello");//new Object different heap spaceString s2 =NewString ("Hello"); String SS1= "Hello";//point to the same constant poolString ss2 = "Hello"; System.out.println (S1==S2); System.out.println (SS1==SS2); String T1= "a"; String T2= T1 + "B"; String T3= "a" + "B"; System.out.println (T2= = "AB");//T1 is a final type string that cannot be changed, such as to change to create a new object T2 is a new object        FinalString tt1= "a"; String TT2=tt1+ "B";//compiler optimization to be able to determine the TT1 as "a" so tt2=tt1+ "B" became tt2= "AB";SYSTEM.OUT.PRINTLN (tt2== "AB"); System.out.println (T3= = "AB");//The compiler put string t3= "a" + "B"; optimized to string t3= "AB";String S= "a" + "B" + "C" + "D"; System.out.println (S= = "ABCD");//only one object "ABCD" is generated    }}

Java Basics Interview question: How do I convert a comma-separated string into an array? String s = "a" + "B" + "C" + "D"; Generate several objects?

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.