2.2 Common class----string processing
1 Public classBijiao {2 3 Public Static voidMain (string[] args) {4String s= "Lina520lina520lina";5 //System.out.println (S.length ());6System.out.println ("ZCW". CompareTo (s));//the difference of the first unequal character7 // -8System.out.println ("Sfsdfsdfsdfdfsdfsdfsdf". CompareTo (s));//a positive number means it's not his substring.9 //7TenSystem.out.println ("Lina". CompareTo (s)); One //-14 ASystem.out.println ("Lina520lina520lina". CompareTo (s)); - //0 -System.out.println ("520". CompareTo (s)); the //-55 - //indicates that the value returned by CompareTo is a positive number, indicating that the string used to invoke the method > parameter passed the string - //The return value is a negative number that describes the string passed by the string < parameter of the calling method - //The return value is 0, and the two string sizes are considered equal + - //System.out.println (S.comparetoignorecase ("Lina")); +}
1 Importjava.util.Arrays;2 3 Public classFeige {4 5 Public Static voidMain (string[] args) {6String s= "Lina520lina520lina";7String str= "520";8String [] ss=s.split (str);9String [] Ss1=s.split ("520");//the split is an array of strings .TenString [] Ss2=s.split ("\\d", 4);//limit cut to 4 segments One //regex: Regular Expression ASystem.out.println (arrays.tostring (ss));//traversal of an array - //[Lina, Lina, Lina] - System.out.println (arrays.tostring (SS2)); the //[Lina,,, Lina520lina] - - - +}
1 Public classHuoqu {2 3 Public Static voidMain (string[] args) {4String s= "Lina520lina520lina";5System.out.println (S.charat (7));//L6System.out.println (S.codepointat (7));//1087System.out.println (S.codepointat (6));// -8System.out.println (S.codepointbefore (7));// -9System.out.println (S.codepointcount (6, 8));//2TenSystem.out.println (S.indexof ("Lina"));//0 OneSystem.out.println (S.indexof (-5));//All is-1 ASystem.out.println (S.indexof ("Lina", 2));//7 -System.out.println (S.lastindexof ("Lina"));// - -System.out.println (S.lastindexof ("Lina", 14));// - theSystem.out.println (S.lastindexof ("Lina", 13));//7 -System.out.println (S.length ());// - -}
1 Public classjiequ {2 3 Public Static voidMain (string[] args) {4String s= "Lina520lina520lina";5System.out.println (S.substring (4));//Intercept from fourth, keep fourth to end, including 4th6 //520lina520lina7System.out.println (S.substring (4, 11));//Intercept from fourth to 11th, excluding 11th8 //520lina9}
1 Public classOther {2 3 4 5 Public Static voidMain (string[] args) {6String s= "ZCWLINA520LINA520LINAZCW";7 System.out.println (S.trim ());8 //ZCWLINA520LINA520LINAZCW9 TenString str= string.valueof (true);//turns a Boolean into a string OneSystem.out.println (str);//true A -String str1=string.valueof (New Char[]{' z ', ' C ', ' W '}); -System.out.println (STR1);//ZCW a character array into a string the - -String str2 =string.valueof (New Char[]{' l ', ' I ', ' n ', ' a '}, 0, 2); -String str21=string.copyvalueof (New Char[]{' l ', ' I ', ' n ', ' a '}, 0, 2); + //String str21=string.copyvalueof (New string[]{"Lina", "520", "ZCW", "520"}, 0, 2);//not - //String str22=string.copyvalueof (New int[]{1,2,3}, 0, 2); +System.out.println (STR2);//Li 第2-1个 A string from the No. 0 position of the string to the position of the ASystem.out.println (STR21);//Li at -System.out.println (String.Format ("a =%d,b =%f,c =%.2f,d=%s", 10,3.1415,3.1415,3.1415)); - - - - inString str3=string.valueof (3.14);//converts a floating-point or shaped data into a string -System.out.println (STR3);//3.14 to + - the * //so is it possible to get the character string of these into the data type to do it? $String string = "123.456";//to ensure that the string is a numeric value, an exception is thrownPanax Notoginseng DoubleD =double.parsedouble (string); - floatf =float.parsefloat (string); the //int I2=int.parseint (string);///No such wording +System.out.println (d);//123.456 ASystem.out.println (f);//123.456 the +String S14 = "314"; - inti = Integer.parseint (S14);//It's not a cosmetic error . $System.out.println (i);//314 $ - - the - Wuyi the - } Wu -}
Javase-----Common Class (1)