String (Java Platform SE 7 ) (original) (raw)

Modifier and Type

Method and Description

char

**[charAt](../../java/lang/String.html#charAt%28int%29)**(int index)

Returns the char value at the specified index.

int

**[codePointAt](../../java/lang/String.html#codePointAt%28int%29)**(int index)

Returns the character (Unicode code point) at the specified index.

int

**[codePointBefore](../../java/lang/String.html#codePointBefore%28int%29)**(int index)

Returns the character (Unicode code point) before the specified index.

int

**[codePointCount](../../java/lang/String.html#codePointCount%28int,%20int%29)**(int beginIndex, int endIndex)

Returns the number of Unicode code points in the specified text range of this String.

int

**[compareTo](../../java/lang/String.html#compareTo%28java.lang.String%29)**([String](../../java/lang/String.html "class in java.lang") anotherString)

Compares two strings lexicographically.

int

**[compareToIgnoreCase](../../java/lang/String.html#compareToIgnoreCase%28java.lang.String%29)**([String](../../java/lang/String.html "class in java.lang") str)

Compares two strings lexicographically, ignoring case differences.

[String](../../java/lang/String.html "class in java.lang")

**[concat](../../java/lang/String.html#concat%28java.lang.String%29)**([String](../../java/lang/String.html "class in java.lang") str)

Concatenates the specified string to the end of this string.

boolean

**[contains](../../java/lang/String.html#contains%28java.lang.CharSequence%29)**([CharSequence](../../java/lang/CharSequence.html "interface in java.lang") s)

Returns true if and only if this string contains the specified sequence of char values.

boolean

**[contentEquals](../../java/lang/String.html#contentEquals%28java.lang.CharSequence%29)**([CharSequence](../../java/lang/CharSequence.html "interface in java.lang") cs)

Compares this string to the specified CharSequence.

boolean

**[contentEquals](../../java/lang/String.html#contentEquals%28java.lang.StringBuffer%29)**([StringBuffer](../../java/lang/StringBuffer.html "class in java.lang") sb)

Compares this string to the specified StringBuffer.

static [String](../../java/lang/String.html "class in java.lang")

**[copyValueOf](../../java/lang/String.html#copyValueOf%28char[]%29)**(char[] data)

Returns a String that represents the character sequence in the array specified.

static [String](../../java/lang/String.html "class in java.lang")

**[copyValueOf](../../java/lang/String.html#copyValueOf%28char[],%20int,%20int%29)**(char[] data, int offset, int count)

Returns a String that represents the character sequence in the array specified.

boolean

**[endsWith](../../java/lang/String.html#endsWith%28java.lang.String%29)**([String](../../java/lang/String.html "class in java.lang") suffix)

Tests if this string ends with the specified suffix.

boolean

**[equals](../../java/lang/String.html#equals%28java.lang.Object%29)**([Object](../../java/lang/Object.html "class in java.lang") anObject)

Compares this string to the specified object.

boolean

**[equalsIgnoreCase](../../java/lang/String.html#equalsIgnoreCase%28java.lang.String%29)**([String](../../java/lang/String.html "class in java.lang") anotherString)

Compares this String to another String, ignoring case considerations.

static [String](../../java/lang/String.html "class in java.lang")

**[format](../../java/lang/String.html#format%28java.util.Locale,%20java.lang.String,%20java.lang.Object...%29)**([Locale](../../java/util/Locale.html "class in java.util") l,[String](../../java/lang/String.html "class in java.lang") format,[Object](../../java/lang/Object.html "class in java.lang")... args)

Returns a formatted string using the specified locale, format string, and arguments.

static [String](../../java/lang/String.html "class in java.lang")

**[format](../../java/lang/String.html#format%28java.lang.String,%20java.lang.Object...%29)**([String](../../java/lang/String.html "class in java.lang") format,[Object](../../java/lang/Object.html "class in java.lang")... args)

Returns a formatted string using the specified format string and arguments.

byte[]

**[getBytes](../../java/lang/String.html#getBytes%28%29)**()

Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.

byte[]

**[getBytes](../../java/lang/String.html#getBytes%28java.nio.charset.Charset%29)**([Charset](../../java/nio/charset/Charset.html "class in java.nio.charset") charset)

Encodes this String into a sequence of bytes using the givencharset, storing the result into a new byte array.

void

**[getBytes](../../java/lang/String.html#getBytes%28int,%20int,%20byte[],%20int%29)**(int srcBegin, int srcEnd, byte[] dst, int dstBegin)

Deprecated.

This method does not properly convert characters into bytes. As of JDK 1.1, the preferred way to do this is via thegetBytes() method, which uses the platform's default charset.

byte[]

**[getBytes](../../java/lang/String.html#getBytes%28java.lang.String%29)**([String](../../java/lang/String.html "class in java.lang") charsetName)

Encodes this String into a sequence of bytes using the named charset, storing the result into a new byte array.

void

**[getChars](../../java/lang/String.html#getChars%28int,%20int,%20char[],%20int%29)**(int srcBegin, int srcEnd, char[] dst, int dstBegin)

Copies characters from this string into the destination character array.

int

**[hashCode](../../java/lang/String.html#hashCode%28%29)**()

Returns a hash code for this string.

int

**[indexOf](../../java/lang/String.html#indexOf%28int%29)**(int ch)

Returns the index within this string of the first occurrence of the specified character.

int

**[indexOf](../../java/lang/String.html#indexOf%28int,%20int%29)**(int ch, int fromIndex)

Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.

int

**[indexOf](../../java/lang/String.html#indexOf%28java.lang.String%29)**([String](../../java/lang/String.html "class in java.lang") str)

Returns the index within this string of the first occurrence of the specified substring.

int

**[indexOf](../../java/lang/String.html#indexOf%28java.lang.String,%20int%29)**([String](../../java/lang/String.html "class in java.lang") str, int fromIndex)

Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.

[String](../../java/lang/String.html "class in java.lang")

**[intern](../../java/lang/String.html#intern%28%29)**()

Returns a canonical representation for the string object.

boolean

**[isEmpty](../../java/lang/String.html#isEmpty%28%29)**()

Returns

true

if, and only if, length() is

0

.

int

**[lastIndexOf](../../java/lang/String.html#lastIndexOf%28int%29)**(int ch)

Returns the index within this string of the last occurrence of the specified character.

int

**[lastIndexOf](../../java/lang/String.html#lastIndexOf%28int,%20int%29)**(int ch, int fromIndex)

Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index.

int

**[lastIndexOf](../../java/lang/String.html#lastIndexOf%28java.lang.String%29)**([String](../../java/lang/String.html "class in java.lang") str)

Returns the index within this string of the last occurrence of the specified substring.

int

**[lastIndexOf](../../java/lang/String.html#lastIndexOf%28java.lang.String,%20int%29)**([String](../../java/lang/String.html "class in java.lang") str, int fromIndex)

Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the specified index.

int

**[length](../../java/lang/String.html#length%28%29)**()

Returns the length of this string.

boolean

**[matches](../../java/lang/String.html#matches%28java.lang.String%29)**([String](../../java/lang/String.html "class in java.lang") regex)

int

**[offsetByCodePoints](../../java/lang/String.html#offsetByCodePoints%28int,%20int%29)**(int index, int codePointOffset)

Returns the index within this String that is offset from the given index bycodePointOffset code points.

boolean

**[regionMatches](../../java/lang/String.html#regionMatches%28boolean,%20int,%20java.lang.String,%20int,%20int%29)**(boolean ignoreCase, int toffset,[String](../../java/lang/String.html "class in java.lang") other, int ooffset, int len)

Tests if two string regions are equal.

boolean

**[regionMatches](../../java/lang/String.html#regionMatches%28int,%20java.lang.String,%20int,%20int%29)**(int toffset,[String](../../java/lang/String.html "class in java.lang") other, int ooffset, int len)

Tests if two string regions are equal.

[String](../../java/lang/String.html "class in java.lang")

**[replace](../../java/lang/String.html#replace%28char,%20char%29)**(char oldChar, char newChar)

Returns a new string resulting from replacing all occurrences ofoldChar in this string with newChar.

[String](../../java/lang/String.html "class in java.lang")

**[replace](../../java/lang/String.html#replace%28java.lang.CharSequence,%20java.lang.CharSequence%29)**([CharSequence](../../java/lang/CharSequence.html "interface in java.lang") target,[CharSequence](../../java/lang/CharSequence.html "interface in java.lang") replacement)

Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence.

[String](../../java/lang/String.html "class in java.lang")

**[replaceAll](../../java/lang/String.html#replaceAll%28java.lang.String,%20java.lang.String%29)**([String](../../java/lang/String.html "class in java.lang") regex,[String](../../java/lang/String.html "class in java.lang") replacement)

Replaces each substring of this string that matches the given regular expression with the given replacement.

[String](../../java/lang/String.html "class in java.lang")

**[replaceFirst](../../java/lang/String.html#replaceFirst%28java.lang.String,%20java.lang.String%29)**([String](../../java/lang/String.html "class in java.lang") regex,[String](../../java/lang/String.html "class in java.lang") replacement)

Replaces the first substring of this string that matches the given regular expression with the given replacement.

[String](../../java/lang/String.html "class in java.lang")[]

**[split](../../java/lang/String.html#split%28java.lang.String%29)**([String](../../java/lang/String.html "class in java.lang") regex)

[String](../../java/lang/String.html "class in java.lang")[]

**[split](../../java/lang/String.html#split%28java.lang.String,%20int%29)**([String](../../java/lang/String.html "class in java.lang") regex, int limit)

boolean

**[startsWith](../../java/lang/String.html#startsWith%28java.lang.String%29)**([String](../../java/lang/String.html "class in java.lang") prefix)

Tests if this string starts with the specified prefix.

boolean

**[startsWith](../../java/lang/String.html#startsWith%28java.lang.String,%20int%29)**([String](../../java/lang/String.html "class in java.lang") prefix, int toffset)

Tests if the substring of this string beginning at the specified index starts with the specified prefix.

[CharSequence](../../java/lang/CharSequence.html "interface in java.lang")

**[subSequence](../../java/lang/String.html#subSequence%28int,%20int%29)**(int beginIndex, int endIndex)

Returns a new character sequence that is a subsequence of this sequence.

[String](../../java/lang/String.html "class in java.lang")

**[substring](../../java/lang/String.html#substring%28int%29)**(int beginIndex)

Returns a new string that is a substring of this string.

[String](../../java/lang/String.html "class in java.lang")

**[substring](../../java/lang/String.html#substring%28int,%20int%29)**(int beginIndex, int endIndex)

Returns a new string that is a substring of this string.

char[]

**[toCharArray](../../java/lang/String.html#toCharArray%28%29)**()

Converts this string to a new character array.

[String](../../java/lang/String.html "class in java.lang")

**[toLowerCase](../../java/lang/String.html#toLowerCase%28%29)**()

Converts all of the characters in this String to lower case using the rules of the default locale.

[String](../../java/lang/String.html "class in java.lang")

**[toLowerCase](../../java/lang/String.html#toLowerCase%28java.util.Locale%29)**([Locale](../../java/util/Locale.html "class in java.util") locale)

Converts all of the characters in this String to lower case using the rules of the given Locale.

[String](../../java/lang/String.html "class in java.lang")

**[toString](../../java/lang/String.html#toString%28%29)**()

This object (which is already a string!) is itself returned.

[String](../../java/lang/String.html "class in java.lang")

**[toUpperCase](../../java/lang/String.html#toUpperCase%28%29)**()

Converts all of the characters in this String to upper case using the rules of the default locale.

[String](../../java/lang/String.html "class in java.lang")

**[toUpperCase](../../java/lang/String.html#toUpperCase%28java.util.Locale%29)**([Locale](../../java/util/Locale.html "class in java.util") locale)

Converts all of the characters in this String to upper case using the rules of the given Locale.

[String](../../java/lang/String.html "class in java.lang")

**[trim](../../java/lang/String.html#trim%28%29)**()

Returns a copy of the string, with leading and trailing whitespace omitted.

static [String](../../java/lang/String.html "class in java.lang")

**[valueOf](../../java/lang/String.html#valueOf%28boolean%29)**(boolean b)

Returns the string representation of the boolean argument.

static [String](../../java/lang/String.html "class in java.lang")

**[valueOf](../../java/lang/String.html#valueOf%28char%29)**(char c)

Returns the string representation of the char argument.

static [String](../../java/lang/String.html "class in java.lang")

**[valueOf](../../java/lang/String.html#valueOf%28char[]%29)**(char[] data)

Returns the string representation of the char array argument.

static [String](../../java/lang/String.html "class in java.lang")

**[valueOf](../../java/lang/String.html#valueOf%28char[],%20int,%20int%29)**(char[] data, int offset, int count)

Returns the string representation of a specific subarray of thechar array argument.

static [String](../../java/lang/String.html "class in java.lang")

**[valueOf](../../java/lang/String.html#valueOf%28double%29)**(double d)

Returns the string representation of the double argument.

static [String](../../java/lang/String.html "class in java.lang")

**[valueOf](../../java/lang/String.html#valueOf%28float%29)**(float f)

Returns the string representation of the float argument.

static [String](../../java/lang/String.html "class in java.lang")

**[valueOf](../../java/lang/String.html#valueOf%28int%29)**(int i)

Returns the string representation of the int argument.

static [String](../../java/lang/String.html "class in java.lang")

**[valueOf](../../java/lang/String.html#valueOf%28long%29)**(long l)

Returns the string representation of the long argument.

static [String](../../java/lang/String.html "class in java.lang")

**[valueOf](../../java/lang/String.html#valueOf%28java.lang.Object%29)**([Object](../../java/lang/Object.html "class in java.lang") obj)

Returns the string representation of the Object argument.