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?