String code example

Source: Internet
Author: User

 PackageLianxi; Public classlianxi0112 { Public Static voidMain (string[] args) {//TODO Auto-generated method stubsString str= "string constant"; String str1=NewString ("string"); CharA[]={' A ', ' B ', ' C ', ' d '}; String str2=NewString (a); System.out.println ("Str2=" +str2); //about the String method//length of string, number of charactersstr.length (); System.out.println ("Str=" +str.length ()); //Connection of Strings +       inti=100; String STR3=i+ ""; //Find StringStr2.indexof ("AB"); System.out.println (Index of A of "abc" = "+str2.indexof" ("a")); System.out.println (Index of AB for "abc" = "+str2.indexof" ("AB")); System.out.println (Index of "abc" AD = "+str2.lastindexof" ("a")); //determine if a string is included       if(Str2.indexof ("AC") >=0) {System.out.println (Contains); }Else{System.out.println ("Does not contain"); }       //look from behind .Str2= "Abcabc"; Str2.lastindexof (A); System.out.println (Index of a of "abcabc" = "+str2.lastindexof" ("a")); //Interception of strings (intercept substrings)Str2.substring (2); System.out.println (Interception of "abcabc" = "+str2.substring" (6)); System.out.println (Interception of "abcabc" = "+str2.substring" (2,4)); //go space before and afterstr2= "ABC ab C"; System.out.println ("Abcabc" The Go space = "+" # "+str2.trim () +" # "); //Find and replaceStr2.replace ("", "space"); System.out.println (Replacement space for "abcabc" = "+str2.replace (" "," Space "))); Str2.replacefirst ("", "space"); System.out.println (Replacement space for "abcabc" = "+str2.replacefirst (" "," Space "))); STR2="     "; if(Str2.trim (). Length () >0) {System.out.println ("With content"); }Else{System.out.println ("No content"); }            //Judging      /*string Stra=new string ("abc");//new keyword will open up new memory space string Strb=new string ("abc");       This can't be judged!! */String stra= "ABC";//the assignment is a constant,String strb= "ABC";//if the constant already exists, then give the address directly to the variable       if(Stra.equals (StrB))//determine if values are equal, case sensitive{System.out.println ("STRA=STRB"); }Else{System.out.println ("STRA!=STRB"); }                     if(Stra.equalsignorecase (StrB))//determine if values are equal, not case-sensitive{System.out.println ("STRA=STRB"); }Else{System.out.println ("STRA!=STRB"); }              //Start JudgingStr2= "ABCdef"; if(Str2.startswith ("ABC") {System.out.println ("STR2 begins with ABC"); }              //End of Judgment       if(Str2.endswith ("F") {System.out.println ("str2 ends with F"); }              //Uppercase and lowercaseSystem.out.println ("str2 Turn lowercase" +str2.tolowercase ()); System.out.println ("STR2 to uppercase" +str2.touppercase ()); String Info= "ABC#20#DEF#GGG";//There is a special delimiter to separate the composed stringString[]in =info.split ("#");  for(String t:in) {System.out.println ("info =" +t); }                 }}

String code example

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.