See Results 1?
Package Com.swift; class arraystring { publicstaticvoid main (string[] args) { = "Swift : 30|sunny:28| Ben:32 "; = Str.split ("\\|" ); for (int i = 0; I <= str1.length-1; i++) { = str1[i].split ("\ \:"); System.out.println ("name is" + str2[0] + "-" + "Age is" + str2[1]); System.out.println (); }}}
See results 2?
PackageCom.swift;classStringemail { Public Static voidMain (string[] args) {String email= "[Email protected]"; String Email1= "[Email protected]"; String Email2= "Tiankong.sina.com"; String email3= "[Email protected]"; String Email4= "[Email protected]"; String EMAIL5="@."; SYSTEM.OUT.PRINTLN (Operate (email)); SYSTEM.OUT.PRINTLN (Operate (EMAIL1)); SYSTEM.OUT.PRINTLN (Operate (EMAIL2)); SYSTEM.OUT.PRINTLN (Operate (EMAIL3)); SYSTEM.OUT.PRINTLN (Operate (EMAIL4)); SYSTEM.OUT.PRINTLN (Operate (EMAIL5)); } Public Static Booleanoperate (String str) {Booleanflag=true; if(Str.indexof ("@") ==-1) {flag=false; } if(Str.indexof (".") ==-1) {flag=false; } if(Str.indexof (".") <=str.indexof ("@") ) {flag=false; } returnFlag; }}
See results 3?
Package Com.swift; class stringequals { publicstaticvoid main (string[] args) { String str= "Hello"; String str1=new string ("Hello"); if (Str.equals (str1)) System.out.println ("111111111"); Else System.out.println ("00000000000");} }
See results 4?
PackageCom.swift; Public classstringresult {String str=NewString ("Good"); Char[] ch = {' A ', ' B ', ' C ' }; Public Static voidMain (String args[]) {Stringresult SR=NewStringresult (); Sr.change (Sr.str, sr.ch); System.out.print (Sr.str+ "and"); System.out.print (sr.ch); } Public voidChange (String str,Charch[]) {STR= "Test OK"; ch[0] = ' g '; }}
See results 5?
PackageCom.swift;classStringjudge { Public Static voidMain (string[] args) {String str1= "Hello"; String str2=NewString ("World"); System.out.println (str1+str2); String a= "OK"; String b= "OK"; String C=NewString ("OK"); if(a==b) System.out.println ("1"); ElseSystem.out.println ("0"); if(a==c) System.out.println ("1"); ElseSystem.out.println ("0"); if(b==c) System.out.println ("1"); ElseSystem.out.println ("0"); if(A.equals (b)) System.out.println ("1"); ElseSystem.out.println ("0"); if(A.equals (c)) System.out.println ("1"); ElseSystem.out.println ("0"); if(B.equals (c)) System.out.println ("1"); ElseSystem.out.println ("0"); }}
How to explain?
The difference is that the first one creates the string "OK" in memory, then assigns the reference to a, the next statement string b = "OK", then the JVM will no longer create "OK", but will directly assign the first "OK" reference to B, i.e., A and B are using the same piece of memory, and string c = new string ("OK"); the JVM will create an area in memory and place the string "OK".
String class strings in Java split into string arrays to determine the results of the mailbox address string comparison?