Java String API

Source: Internet
Author: User

Java.lang Package:

String;


/*java String

* The string object will not change once it has created its contents

*

*

*/

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 length

Obj.charat (int index); Returns the corresponding character of the subscript

Quest Leads

Obj.indexof (int ch) returns the index at the first occurrence of the specified character in this string

indexOf (int ch, int fromIndex) returns the index at the first occurrence of the specified character in this string and searches starting at the specified index

IndexOf (String str) returns the index of the first occurrence of the specified substring in this string

IndexOf (String str, int fromIndex) returns the index of the first occurrence of the specified substring in this string, starting at the specified index


IsEmpty () returns True if and only if length () is 0 o'clock


lastIndexOf (int ch) returns the index of the last occurrence of the specified character in this string, or 1 if it does not appear as a substring.


lastIndexOf (int ch, int fromIndex) returns the index at the last occurrence of the specified character in this string, starting at the specified index to reverse-search


LastIndexOf (String str) returns the index of the rightmost occurrence of the specified substring in this string

LastIndexOf (String str, int fromIndex) returns the index of the last occurrence of the specified substring in this string, starting at the specified index to reverse the search

To find a child string

substring (int beginindex) returns a new string that is a substring of this string

substring (int beginindex, int endIndex) returns a new string that is a substring of this string (not including EndIndex)

Cutting of strings

Split (string regex) splits this string based on the match of the given regular expression.

Split (string regex, int limit) splits this string based on the match of the given regular expression.


ToCharArray () Converts this string to a new character array.


GetBytes () encodes this String into a byte sequence using the platform's default character set and stores the result in a new byte array


GetBytes (Charset Charset) encodes this String into a byte sequence using the given Charset and stores the result in a new byte array.


Case conversion:

toLowerCase () converts all characters in this String to lowercase using the default locale's rules.

toUpperCase () converts all characters in this String to uppercase using the default locale's rules.


Replace:

Replace (char OldChar, char Newchar) returns a new string that is obtained by replacing all OldChar that appear in this string with Newchar.


ReplaceAll (string regex, string replacement) replaces this string with the given replacement with all substrings that match the given regular expression.


Trim () Returns a copy of the string, ignoring leading and trailing blanks.


Concat (String str) connects the specified string to the end of this string


ValueOf ()


Judge:

Equals (Object anobject) Compare content

Equalsignorecase (String anotherstring) compares this string to another string, regardless of case.


Contains (Charsequence s) returns True when and only if this string contains a sequence of specified char values (char characters are composed of sequences).


EndsWith (string suffix) tests whether this string ends with the specified suffix.

StartsWith (string prefix) tests whether this string starts with the specified prefix.

Comparison:

CompareTo (String anotherstring) compares two strings in a dictionary order

Comparetoignorecase (String str) compares two strings in a dictionary order, regardless of the case.














Java String API

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.