Java String API

Source: Internet
Author: User

Java String API
Java. lang Package: String;/* java String * the content of a String object is not changed once it is created. ***/Construct: String (byte [] bytes) String (byte [] bytes, int offset, int length) String (char [] value) String (char [] value, int offset, int count) Method: String obj = new String (); obj. length () Get the length obj. charAt (int index); returns the search result obj for the character corresponding to the subscript. indexOf (int ch) returns the index indexOf (int ch, int fromIndex) at the first occurrence of the specified character in this string. returns the index at the first occurrence of the specified character in this string, search for indexOf (String st) from the specified index R) returns the index indexOf (String str, int fromIndex) of the first occurrence of the substring. returns the index of the first occurrence of the substring, starting from the specified index, isEmpty () returns true lastIndexOf (int ch) only when length () is 0 and returns the index at the last occurrence of the specified character in this string, if it does not appear as a substring,-1 is returned. LastIndexOf (int ch, int fromIndex) returns the index of the last occurrence of the specified character in this String, and searches for lastIndexOf (String str) from the specified index) returns the index lastIndexOf (String str, int fromIndex) at the rightmost occurrence of the substring and returns the index at the last occurrence of the substring, returns a new string from the specified index. It is a substring of this string, substring (int beginIndex, int endIndex) returns a new String, which is a substring of this String (excluding endIndex). split (String regex) splits the String based on the matching of the given regular expression. Split (String regex, int limit) splits the String based on the matching regular expression. ToCharArray () converts this string into a new character array. GetBytes () uses the default Character Set of the platform to encode this String as a byte sequence and store the result to a new byte array getBytes (Charset charset) encode the String to the byte sequence using the given charset and store the result to the new byte array. Case-insensitive conversion: toLowerCase () converts all characters in this String to lowercase using the rules of the default language environment. ToUpperCase () converts all characters in this String to uppercase using the rules of the default language environment. Replace: replace (char oldChar, char newChar) returns a new String, which is the replaceAll (String regex, String replacement) obtained by replacing all the oldChar in this String with newChar) replace all the substrings matching the given regular expression with the given replacement. Trim () returns a copy of the string, ignoring leading and trailing spaces. Concat (String str) connects the specified String to the end of this String valueOf () Judgment: equals (Object anObject) compares the String with the end of another String, case Insensitive. Contains (CharSequence s) returns true if and only if the string contains the specified char value sequence (a sequence composed of char characters. EndsWith (String suffix) tests whether the String ends with the specified suffix. StartsWith (String prefix) tests whether the String starts with the specified prefix. Comparison: compareTo (String anotherString) compares two strings in alphabetical order by comparing the compareToIgnoreCase (String str), regardless of Case sensitivity.

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.