Various methods and operations of Java string

Source: Internet
Author: User

No.

Method name

Function

Characters and strings

01

Public String (char[] value)

Converts all contents of a character array into a string

02

Public String (char[] value,int offset,int count)

Converts part of a character array into a string

03

public char charAt (int index)

Gets the character at the specified index, starting at 0

04

Public char[] ToCharArray ()

Returns a string into a character array

Bytes and strings

01

Public String (byte[] bytes)

Converts everything in a byte array into a string

02

Public String (byte[] bytes,int offset,int length)

Converts part of a byte array into a string

03

Public byte[] GetBytes ()

Returns a string in the form of a byte array

04

Public byte[] GetBytes (String charsetname) throws Unsupportedencodingexcepetion

Encoding conversion processing

string comparison

01

public boolean equals (String anobject)

Case-sensitive comparisons

02

public boolean equalsignorecase (String anotherstring)

Case-insensitive comparison

03

public int CompareTo (String anotherstring)

Compare the size relationships of two strings

String Lookup

01

Public Boolean contains (String s)

Determine if a substring exists

02

public int indexOf (String str)

Find the position of the specified character from the beginning, find the starting index of the return position, do not find the return-1

03

public int indexOf (String str,int fromIndex)

Find the location of a sub-character from a specified location

04

public int LastIndex (String str)

Find the location of the sub-character from the back forward

05

public int LastIndex (String str,int fromIndex)

Finds the location of a sub-character from the specified position, backward forward

06

public boolean startsWith (String prefix)

Start from the beginning to determine whether to start with the specified string

07

public boolean startsWith (String prefix,int toffset)

Starts at the specified position to determine whether to start with the specified string

08

public boolean endsWith (String suffix)

Determines whether to end with the specified string

String substitution

01

public string ReplaceAll (string regex,string replacement)

Replace All content

02

public string Replacefirst (string regex,string replacement)

Replace the first content

String splitting

01

Public string[] Split (String regex)

Splitting a string all

02

Public string[] Split (String regex,int limit)

Splits the string part, the length of which is the limit

String interception

01

Public String substring (int beginindex)

Intercept from the specified index to the end

02

Public String substring (int beginindex,int endIndex)

Intercept part of the content

Other operations

01

Public String trim ()

Remove the left and right spaces in the string, leaving the middle space

02

Public String toUpperCase ()

String to uppercase

03

Public String toLowerCase ()

String to lowercase

04

Public String interm ()

String into Object pool

05

public string concat (String str)

String connection, equivalent to "+"

06

public int Length ()

Get string length

07

public boolean inempty ()

Determines whether it is empty (not NULL, but length is empty)

Various methods and operations of Java string

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.