Common methods of Java Foundation--string

Source: Internet
Author: User

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

Related Article

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.