Examples of the common methods of string in Java 1, Length () string: Char chars[]={' A ', ' B '. ' C '}; String S=new string (chars); int Len=s.length (); 2, charAt () intercept one character example: Char ch; Ch= "abc". CHARAT (1); Return ' B '
3. GetChars () intercepts multiple character examples: String s= "This is a demo of the GetChars method."; Char Buf[]=new char[20]; S.getchars (10,14,buf,0);
4. One way to replace GetChars () with GetBytes () is to store characters in a byte array, which is getBytes ().
5, ToCharArray ()
6, Equals ()
Determines whether the values of two strings are equal
equalsignorecase ()
Determines whether the value of two strings is equal and ignores case
7, regionmatches ()Used to compare a particular area of a string with another specific area, which has an overloaded form that allows the case to be ignored in comparisons.
8, StartsWith () and EndsWith ()The StartsWith () method determines whether to start with a specific string, and the Endwith () method determines whether to end with a specific string
9, equals () and = = The Equals () method compares the characters in a string object, and the = = operator Compares whether two objects refer to the same instance. Example: String s1= "Hello"; String S2=new string (S1); S1.eauals (S2); True S1==s2;//false
10, CompareTo () and Comparetoignorecase () Comparing strings
11, IndexOf () and LastIndexOf () indexOf () Find the first occurrence of a character or substring. LastIndexOf () finds the character or substring that is the last occurrence. 12, SUBSTRING () It has two forms, the first is: string substring (int startIndex) The second type is: string substring (int startindex,int endIndex) 13 , Concat () connects two strings 14, replace () replaces it in two forms, the first of which is replaced with a character in all occurrences of a character in the calling string, as follows: String replace (char Original,char REPL Acement) For example: String s= "Hello". Replace (' l ', ' w '); The second form is to replace another sequence of characters with one character sequence, as follows: String replace (charsequence original,charsequence replacement) 15, trim () strips the starting and ending spaces 16, Convert ValueOf () to String 17, tolowercase () to lowercase 18, touppercase () to uppercase
Common methods of Java Foundation--string