Java--string class

Source: Internet
Author: User
Tags array length

OneString Common Methods
1 Importjava.util.Arrays;2 3  Public classStringdemo {4      Public Static voidMain (string[] args) {5String str = "String Method";6         //determines whether a string is empty7 str.isempty ();8         //Get string length9 str.length ();Ten         //remove the opening and closing spaces One Str.trim (); A  -         //finds the first found character or string index position in string 0 to the end, no return-1 -         //public int indexOf (String str) the         //public int indexOf (int ch) -         intindex = str.indexof ("ing");//3 -index = str.indexof (' i ');//3 -         //FromIndex from this index (contains) the location of the search, that is, FromIndex to the end +         //public int indexOf (int ch, fromIndex) -         //public int indexOf (String ch, fromIndex) +index = str.indexof (' i ', 3);//3 A         //LastIndexOf, similar to the IndexOf method, looks from the back to index 0 atindex = str.lastindexof (' i '); -  -         //whether the string contains the specified sequence of characters, string is the implementation of the interface Charsequence -         //Public Boolean contains (charsequence s) -         //internal is realization: return IndexOf (S.tostring ()) >-1; -         Booleanct = str.contains ("ing");//true in  -         //determines whether a string begins with a given substring to         //Public boolean startsWith (String prefix) +         Booleanst = Str.startswith ("str");//true -         //Public boolean startsWith (String prefix, int toffset) the         //Toffset indicates the starting position *st = Str.startswith ("str", 2);//false $         //determines whether a string ends with a given substringPanax Notoginseng         //Public boolean endsWith (String suffix) -         Booleaned = str.endswith ("FA");//true the  +         //compare with other strings to see if the content is the same A         //Public Boolean equals (Object anobject) the  +         //Ignore case, compare with other strings to see if content is the same -         //Public Boolean equalsignorecase (String anotherstring) $"abc". Equals ("abc");//false $"ABC". EQUALSIGNORECASE ("abc");//true -  -         //turn case, return new string, original string unchanged theStr.tolowercase ();//lowercase -Str.touppercase ();//UppercaseWuyi  the         //string comparison size, according to the encoded value -         //public int CompareTo (String anotherstring) Wu"ABC". COMPARETO ("abc");//+ = Return ' A '-' a ' character by comparison -         //Ignore letter Case for comparison (both turn uppercase and then Compare) About         //public int comparetoignorecase (String str) $  -         //intercepts a string to return a new string -         //Public String substring (int beginindex) -         //Public String substring (int beginindex, int endIndex) A         //Index of beginindex start index EndIndex end +         //Beginindex are included in the interception range, while Endindex does not include theString sub = str.substring (1);//Tring Method -String Sube = str.substring (1, 2);//T $  the         //string concatenated, returns the current string and the string after the argument string is merged, the original string is unchanged the         //Public string concat (String str) theString cc = Str.concat ("--concat connection method"); the         //String Method--Concat connection method -  in         //string substitution, return new string, original string unchanged the         //Replace a single character the         //Public String Replace (char OldChar, char Newchar) AboutString RP = str.replace (' square ', ' Circle ');//String Round Method the         //Replace character sequence the         //Public String replace (charsequence target, charsequence replacement) theRP = str.replace ("String", "replace");//Replace Method +         //use regular to select the characters you want to replace -         //regex-to-regular-expression string the         //replacement replaced elementsBayi         //Public string ReplaceAll (string regex, string replacement) theRP = Str.replaceall ("[A-Z]", "I");//Siiiii Method the         //indicates: will match to each lowercase letter, change to I -         //Replacefirst Changing a string that meets the requirements for the first time -RP = Str.replacefirst ("[A-Z]", "I"); the  the         //separates strings, returns an array of delimited substrings, the original string unchanged the         //The regex is separated by a string and the matched string is removed the         //Public string[] Split (String regex) -string[] STRs = "HELLO World This Night". Split (""); the System.out.println (Arrays.aslist (STRs)); the         //[HELLO, World, this, night] theSTRs = "HELLO World This Night". Split ("H");94 System.out.println (Arrays.aslist (STRs)); the         //[, Ello World T, is Nig, T] the  the         //limit delimited number of limits (LIMIT-1)98         //It can also be understood that the number of matches to the regex is limit-1 About         //if the number of limits (LIMIT-1) is greater than the number of actual separators -         //or limit-1 < 0101         //then the normal separation is unrestricted. 102         //"HELLO World This Night". Split ("") such a separation103         //Public string[] Split (string regex, string limit);104          for(inti =-1; I < 6; i++) { theSTRs = "HELLO World This Night". Split ("", i);106 System.out.println (Arrays.aslist (STRs));107         }108         /**109 * can actually be separated 3 times, can be obtained array length of 4 the          * 111 *-1 [HELLO, World, this, night] the * 0 [HELLO, World, this, night]113 * 1 [HELLO World This Night] the * 2 [HELLO, World this night] the * 3 [HELLO, World, this night] the * 4 [HELLO, World, this, night]117 * 5 [HELLO, World, this, night]118          */119     } - 121}
Two, the construction method of String

Java--string class

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.