Java String Common functions

Source: Internet
Author: User

String

1. Char charAt (int index) : Takes one of the characters in the string, where the argument index refers to the ordinal in the string. The ordinal number of the string starts from 0 to length ()-1 .

2. int CompareTo (string anotherstring) : The current String object is compared to anotherstring . The equality relationship returns 0; When unequal, the first unequal character difference is returned, starting with the 0 characters of the two strings, and in the other case, the earlier part of the longer string happens to be a shorter string, returning their length difference.

4. String concat (String str) : Connects the string object to str .

9. Boolean Equals (Object AnObject) : Returns truewhen anobject is not empty and is the same as the current String object; false.

int indexOf (int ch) : Only the first match character position is found.

int indexOf (int ch, int fromIndex) : Find the first matching character position starting from FromIndex .

. int indexOf (String str) : Only the first match string position is found.

indexOf Int (string str, int fromIndex) : Find the first match string position starting from FromIndex .

. int lastIndexOf (int ch)

int. int lastIndexOf (int ch, int fromIndex)

. int lastIndexOf (String str)

lastIndexOf Int (String str, int fromIndex) more than four methods are similar to the three, The difference is: find the last matching content.

. int length () : Returns the current string length.

String Replace (char OldChar, char Newchar) : Replaces the first OldChar in a character string with Newchar.

string substring (int beginindex) : Takes a substring from the beginindex position to the end.

26.String substring (int beginindex, int endIndex) : Takes substrings from the beginindex position to the endIndex position.

1), the string length obtained is:Endindex–beginindex;

2), starting from Beginindex , to the end of EndIndex , starting from 0 of the number, which does not include the endIndex position of the character ;

string toLowerCase () : Converts a string to lowercase.

String touppercase () : Converts a string to uppercase.


Publicstring Trim ()

Returns the string after which the string is stripped of the beginning and trailing spaces

Publicstring[] Split (String regex)

Separates a string by the specified delimiter, returning a delimited array of strings

Java String Common functions

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.