PackageStringuse; Public classStringuse { Public Static voidMain (string[] args) {//Get//Indexof,charat (i), length (), SUBSTRING,String a1 = "Hello"; SOP (A1.indexof ("O", 2));//4SOP (A1.indexof ("El"));//1SOP (A1.charat (1));//eSOP (A1.length ());//5SOP (A1.substring (1,4));//ell//JudgingSOP (A1.isempty ());//falseSOP (A1.contains ("Llo"));//trueSOP (A1.startswith ("he"));//trueSOP (A1.equals ("Hello"));//trueSOP (A1.equalsignorecase ("HELLo"));//true//ConversionString string1 = "Hello C + +"; SOP (String1.touppercase ()); //HELLO C + +SOP (string1);//Hello C + +SOP (String1.trim ());//Hello C + +//ReplaceString str1 = "Hello,java"; String str2= Str1.replace ("java", "C + +"); SOP ("str1=" +str1);//Str1=hello,javaSOP ("str2=" +str2);//str2=hello,c++//SplitString sentence = "Abbbcedbfstbbgk"; String[] Arr= Sentence.split ("B"); SOP ("Arr.length=" +arr.length);//7 for(inti = 0; i<arr.length; i++) {SOP (arr[i]); } //trans, string and character array conversionsString Strarr = "Abcdfeg"; Char[] Array =Strarr.tochararray (); for(inti = 0; i<array.length; i++) {SOP (array[i]); } Char[] array2 = {' A ', ' B ', ' C ', ' d ', ' e ', ' F '}; String Arrstr=NewString (Array2, 1, 5); SOP (ARRSTR); //Bcdef//CompareToString dang1 = "Esun"; String dang2= "Gsuz"; SOP (Dang1.compareto (dang2)); //-2//valueOf intnum = 12345; String Val=string.valueof (num); SOP (Val); SOP (Val.length ()); //5, judging by the number of digits } Public Static voidsop (Object obj) {System.out.println (obj); }}
Common methods of the string class