java.lang.Object | |
↳ | java.lang.String |
An immutable sequence of characters/code units (char
s). A
String
is represented by array of UTF-16 values, such that
Unicode supplementary characters (code points) are stored/encoded as
surrogate pairs via Unicode code units (char
).
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Comparator<String> | CASE_INSENSITIVE_ORDER | A comparator ignoring the case of the characters. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates an empty string.
| |||||||||||
Converts the byte array to a string using the default encoding as
specified by the file.encoding system property.
| |||||||||||
This constructor is deprecated.
Use
String(byte[]) or
String(byte[], String) instead.
| |||||||||||
Converts the byte array to a string using the default encoding as
specified by the file.encoding system property.
| |||||||||||
This constructor is deprecated.
Use
String(byte[], int, int) instead.
| |||||||||||
Converts the byte array to a string using the specified encoding.
| |||||||||||
Converts the byte array to a string using the specified encoding.
| |||||||||||
Initializes this string to contain the characters in the specified
character array.
| |||||||||||
Initializes this string to contain the specified characters in the
character array.
| |||||||||||
Creates a
String that is a copy of the specified string. | |||||||||||
Creates a
String from the contents of the specified
StringBuffer . | |||||||||||
Creates a
String from the sub-array of Unicode code points. | |||||||||||
Creates a
String from the contents of the specified StringBuilder . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns the character at the specified offset in this string.
| |||||||||||
Retrieves the Unicode code point (character) value at the specified
index . | |||||||||||
Retrieves the Unicode code point value that precedes the specified
index . | |||||||||||
Calculates the number of Unicode code points between
beginIndex
and endIndex . | |||||||||||
Compares the specified string to this string using the Unicode values of
the characters.
| |||||||||||
Compares the specified string to this string using the Unicode values of
the characters, ignoring case differences.
| |||||||||||
Concatenates this string and the specified string.
| |||||||||||
Determines if this
String contains the sequence of characters in
the CharSequence passed. | |||||||||||
Returns whether the characters in the StringBuffer
strbuf are the
same as those in this string. | |||||||||||
Compares a
CharSequence to this String to determine if
their contents are equal. | |||||||||||
Creates a new string containing the characters in the specified character
array.
| |||||||||||
Creates a new string containing the specified characters in the character
array.
| |||||||||||
Compares the specified string to this string to determine if the
specified string is a suffix.
| |||||||||||
Compares the specified object to this string and returns true if they are
equal.
| |||||||||||
Compares the specified string to this string ignoring the case of the
characters and returns true if they are equal.
| |||||||||||
Returns a localized formatted string, using the supplied format and arguments,
using the user's default locale.
| |||||||||||
Returns a formatted string, using the supplied format and arguments,
localized to the given locale.
| |||||||||||
This method is deprecated.
Use
getBytes() or getBytes(String)
| |||||||||||
Converts this string to a byte array using the default encoding as
specified by the file.encoding system property.
| |||||||||||
Converts this string to a byte array using the specified encoding.
| |||||||||||
Copies the specified characters in this string to the character array
starting at the specified offset in the character array.
| |||||||||||
Returns an integer hash code for this object.
| |||||||||||
Searches in this string for the index of the specified character.
| |||||||||||
Searches in this string for the first index of the specified character.
| |||||||||||
Searches in this string for the index of the specified string.
| |||||||||||
Searches in this string for the first index of the specified string.
| |||||||||||
Searches an internal table of strings for a string equal to this string.
| |||||||||||
Searches in this string for the last index of the specified character.
| |||||||||||
Searches in this string for the last index of the specified string.
| |||||||||||
Searches in this string for the index of the specified string.
| |||||||||||
Searches in this string for the index of the specified character.
| |||||||||||
Returns the size of this string.
| |||||||||||
Determines whether this string matches a given regular expression.
| |||||||||||
Returns the index within this object that is offset from
index by
codePointOffset code points. | |||||||||||
Compares the specified string to this string and compares the specified
range of characters to determine if they are the same.
| |||||||||||
Compares the specified string to this string and compares the specified
range of characters to determine if they are the same.
| |||||||||||
Copies this string replacing occurrences of the specified character with
another character.
| |||||||||||
Copies this string replacing occurrences of the specified target sequence
with another sequence.
| |||||||||||
Replace any substrings within this string that match the supplied regular
expression
expr , with the string substitute . | |||||||||||
Replace the first substring within this string that matches the supplied
regular expression
expr , with the string substitute . | |||||||||||
Splits this string using the supplied regular expression
expr . | |||||||||||
Splits this string using the supplied regular expression
expr . | |||||||||||
Compares the specified string to this string, starting at the specified
offset, to determine if the specified string is a prefix.
| |||||||||||
Compares the specified string to this string to determine if the
specified string is a prefix.
| |||||||||||
Has the same result as the substring function, but is present so that
string may implement the CharSequence interface.
| |||||||||||
Copies a range of characters into a new string.
| |||||||||||
Copies a range of characters into a new string.
| |||||||||||
Copies the characters in this string to a character array.
| |||||||||||
Converts this string to lowercase, using the rules of the specified locale.
| |||||||||||
Converts this string to lowercase, using the rules of the default locale.
| |||||||||||
Returns this string.
| |||||||||||
Converts the characters in this string to uppercase, using the specified
Locale.
| |||||||||||
Converts the characters in this string to uppercase, using the default
Locale.
| |||||||||||
Copies this string removing white space characters from the beginning and
end of the string.
| |||||||||||
Converts the specified float to its string representation.
| |||||||||||
Converts the specified boolean to its string representation.
| |||||||||||
Converts the specified double to its string representation.
| |||||||||||
Converts the specified character to its string representation.
| |||||||||||
Creates a new string containing the characters in the specified character
array.
| |||||||||||
Creates a new string containing the specified characters in the character
array.
| |||||||||||
Converts the specified long to its string representation.
| |||||||||||
Converts the specified integer to its string representation.
| |||||||||||
Converts the specified object to its string representation.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
| |||||||||||
From interface java.lang.CharSequence
| |||||||||||
From interface java.lang.Comparable
|
A comparator ignoring the case of the characters.
Converts the byte array to a string using the default encoding as specified by the file.encoding system property. If the system property is not defined, the default encoding is ISO8859_1 (ISO-Latin-1). If 8859-1 is not available, an ASCII encoding is used.
data | the byte array to convert to a string. |
---|
This constructor is deprecated.
Use String(byte[])
or
String(byte[], String)
instead.
Converts the byte array to a string, setting the high byte of every character to the specified value.
data | the byte array to convert to a string. |
---|---|
high | the high byte to use. |
NullPointerException | when data is null . |
---|
Converts the byte array to a string using the default encoding as specified by the file.encoding system property. If the system property is not defined, the default encoding is ISO8859_1 (ISO-Latin-1). If 8859-1 is not available, an ASCII encoding is used.
data | the byte array to convert to a string. |
---|---|
start | the starting offset in the byte array. |
length | the number of bytes to convert. |
NullPointerException | when data is null . |
---|---|
IndexOutOfBoundsException | if length < 0, start < 0 or start + length >
data.length .
|
This constructor is deprecated.
Use String(byte[], int, int)
instead.
Converts the byte array to a string, setting the high byte of every character to the specified value.
data | the byte array to convert to a string. |
---|---|
high | the high byte to use. |
start | the starting offset in the byte array. |
length | the number of bytes to convert. |
NullPointerException | when data is null . |
---|---|
IndexOutOfBoundsException | if length < 0, start < 0 or
start + length > data.length |
Converts the byte array to a string using the specified encoding.
data | the byte array to convert to a string. |
---|---|
start | the starting offset in the byte array. |
length | the number of bytes to convert. |
encoding | the encoding. |
NullPointerException | when data is null . |
---|---|
IndexOutOfBoundsException | if length < 0, start < 0 or start + length >
data.length . |
UnsupportedEncodingException | if encoding is not supported.
|
Converts the byte array to a string using the specified encoding.
data | the byte array to convert to a string. |
---|---|
encoding | the encoding. |
NullPointerException | when data is null . |
---|---|
UnsupportedEncodingException | if encoding is not supported.
|
Initializes this string to contain the characters in the specified character array. Modifying the character array after creating the string has no effect on the string.
data | the array of characters. |
---|
NullPointerException | when data is null .
|
---|
Initializes this string to contain the specified characters in the character array. Modifying the character array after creating the string has no effect on the string.
data | the array of characters. |
---|---|
start | the starting offset in the character array. |
length | the number of characters to use. |
NullPointerException | when data is null . |
---|---|
IndexOutOfBoundsException | if length < 0, start < 0 or start + length >
data.length
|
Creates a String
that is a copy of the specified string.
string | the string to copy. |
---|
Creates a String
from the contents of the specified
StringBuffer
.
stringbuffer | the buffer to get the contents from. |
---|
Creates a String
from the sub-array of Unicode code points.
codePoints | the array of Unicode code points to convert. |
---|---|
offset | the inclusive index into codePoints to begin
converting from. |
count | the number of elements in codePoints to copy. |
NullPointerException | if codePoints is null . |
---|---|
IllegalArgumentException | if any of the elements of codePoints are not valid
Unicode code points. |
IndexOutOfBoundsException | if offset or count are not within the bounds
of codePoints . |
Creates a String
from the contents of the specified StringBuilder
.
sb | the StringBuilder to copy the contents from. |
---|
NullPointerException | if sb is null . |
---|
Returns the character at the specified offset in this string.
index | the zero-based index in this string. |
---|
IndexOutOfBoundsException | if index < 0 or index >= length() .
|
---|
Retrieves the Unicode code point (character) value at the specified
index
.
index | the index to the char code unit within this string. |
---|
IndexOutOfBoundsException | if index is negative or greater than or equal to
length() . |
---|
Retrieves the Unicode code point value that precedes the specified
index
.
index | the index to the char code unit within this string. |
---|
IndexOutOfBoundsException | if index is less than 1 or greater than
length() . |
---|
Calculates the number of Unicode code points between beginIndex
and endIndex
.
beginIndex | the inclusive beginning index of the subsequence. |
---|---|
endIndex | the exclusive end index of the subsequence. |
IndexOutOfBoundsException | if beginIndex is negative or greater than endIndex or endIndex is greater than length() . |
---|
Compares the specified string to this string using the Unicode values of the characters. Returns 0 if the strings contain the same characters in the same order. Returns a negative integer if the first non-equal character in this string has a Unicode value which is less than the Unicode value of the character at the same position in the specified string, or if this string is a prefix of the specified string. Returns a positive integer if the first non-equal character in this string has a Unicode value which is greater than the Unicode value of the character at the same position in the specified string, or if the specified string is a prefix of this string.
string | the string to compare. |
---|
NullPointerException | if string is null .
|
---|
Compares the specified string to this string using the Unicode values of the characters, ignoring case differences. Returns 0 if the strings contain the same characters in the same order. Returns a negative integer if the first non-equal character in this string has a Unicode value which is less than the Unicode value of the character at the same position in the specified string, or if this string is a prefix of the specified string. Returns a positive integer if the first non-equal character in this string has a Unicode value which is greater than the Unicode value of the character at the same position in the specified string, or if the specified string is a prefix of this string.
string | the string to compare. |
---|
NullPointerException | if string is null .
|
---|
Concatenates this string and the specified string.
string | the string to concatenate |
---|
Determines if this String
contains the sequence of characters in
the CharSequence
passed.
cs | the character sequence to search for. |
---|
true
if the sequence of characters are contained in this
string, otherwise false
.Returns whether the characters in the StringBuffer strbuf
are the
same as those in this string.
strbuf | the StringBuffer to compare this string to. |
---|
true
if the characters in strbuf
are identical to
those in this string. If they are not, false
will be
returned.NullPointerException | if strbuf is null . |
---|
Compares a CharSequence
to this String
to determine if
their contents are equal.
cs | the character sequence to compare to. |
---|
true
if equal, otherwise false
Creates a new string containing the characters in the specified character array. Modifying the character array after creating the string has no effect on the string.
data | the array of characters. |
---|
NullPointerException | if data is null .
|
---|
Creates a new string containing the specified characters in the character array. Modifying the character array after creating the string has no effect on the string.
data | the array of characters. |
---|---|
start | the starting offset in the character array. |
length | the number of characters to use. |
NullPointerException | if data is null . |
---|---|
IndexOutOfBoundsException | if length < 0, start < 0 or start + length >
data.length .
|
Compares the specified string to this string to determine if the specified string is a suffix.
suffix | the suffix to look for. |
---|
true
if the specified string is a suffix of this string,
false
otherwise.NullPointerException | if suffix is null .
|
---|
Compares the specified object to this string and returns true if they are equal. The object must be an instance of string with the same characters in the same order.
object | the object to compare. |
---|
true
if the specified object is equal to this string,
false
otherwise.Compares the specified string to this string ignoring the case of the characters and returns true if they are equal.
string | the string to compare. |
---|
true
if the specified string is equal to this string,
false
otherwise.
Returns a localized formatted string, using the supplied format and arguments, using the user's default locale.
Note that this method can be dangerous: the user's default locale may
not be the locale you tested in, and this may have unexpected effects on
the output. In particular, floating point numbers may be output with
',' instead of '.' as the decimal separator if that's what the user's
locale dictates. If you're formatting a string other than for human
consumption, you should use the format(Locale, String, Object...)
overload and supply Locale.US
.
format | a format string. |
---|---|
args | arguments to replace format specifiers (may be none). |
NullPointerException | if format is null . |
---|---|
IllegalFormatException | if the format is invalid. |
Returns a formatted string, using the supplied format and arguments, localized to the given locale.
Note that this is a convenience method. Using it involves creating an
internal Formatter
instance on-the-fly, which is
somewhat costly in terms of memory and time. This is probably acceptable
if you use the method only rarely, but if you rely on it for formatting a
large number of strings, consider creating and reusing your own
Formatter
instance instead.
loc | the locale to apply; null value means no localization. |
---|---|
format | a format string. |
args | arguments to replace format specifiers (may be none). |
NullPointerException | if format is null . |
---|---|
IllegalFormatException | if the format is invalid. |
This method is deprecated.
Use getBytes()
or getBytes(String)
Converts this string to a byte array, ignoring the high order bits of each character.
start | the starting offset of characters to copy. |
---|---|
end | the ending offset of characters to copy. |
data | the destination byte array. |
index | the starting offset in the destination byte array. |
NullPointerException | if data is null . |
---|---|
IndexOutOfBoundsException | if start < 0 , end > length() , index <
0 or end - start > data.length - index . |
Converts this string to a byte array using the default encoding as specified by the file.encoding system property. If the system property is not defined, the default encoding is ISO8859_1 (ISO-Latin-1). If 8859-1 is not available, an ASCII encoding is used.
Converts this string to a byte array using the specified encoding.
encoding | the encoding to use. |
---|
UnsupportedEncodingException | if the encoding is not supported. |
---|
Copies the specified characters in this string to the character array starting at the specified offset in the character array.
start | the starting offset of characters to copy. |
---|---|
end | the ending offset of characters to copy. |
buffer | the destination character array. |
index | the starting offset in the character array. |
NullPointerException | if buffer is null . |
---|---|
IndexOutOfBoundsException | if start < 0 , end > length() , start >
end , index < 0 , end - start > buffer.length -
index
|
Returns an integer hash code for this object. By contract, any two
objects for which equals(Object)
returns true
must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Searches in this string for the index of the specified character. The search for the character starts at the specified offset and moves towards the end of this string.
c | the character to find. |
---|---|
start | the starting offset. |
Searches in this string for the first index of the specified character. The search for the character starts at the beginning and moves towards the end of this string.
c | the character to find. |
---|
Searches in this string for the index of the specified string. The search for the string starts at the specified offset and moves towards the end of this string.
subString | the string to find. |
---|---|
start | the starting offset. |
NullPointerException | if subString is null .
|
---|
Searches in this string for the first index of the specified string. The search for the string starts at the beginning and moves towards the end of this string.
string | the string to find. |
---|
NullPointerException | if string is null .
|
---|
Searches an internal table of strings for a string equal to this string. If the string is not in the table, it is added. Returns the string contained in the table which is equal to this string. The same string object is always returned for strings which are equal.
Searches in this string for the last index of the specified character. The search for the character starts at the end and moves towards the beginning of this string.
c | the character to find. |
---|
Searches in this string for the last index of the specified string. The search for the string starts at the end and moves towards the beginning of this string.
string | the string to find. |
---|
NullPointerException | if string is null .
|
---|
Searches in this string for the index of the specified string. The search for the string starts at the specified offset and moves towards the beginning of this string.
subString | the string to find. |
---|---|
start | the starting offset. |
NullPointerException | if subString is null .
|
---|
Searches in this string for the index of the specified character. The search for the character starts at the specified offset and moves towards the beginning of this string.
c | the character to find. |
---|---|
start | the starting offset. |
Returns the size of this string.
Determines whether this string matches a given regular expression.
expr | the regular expression to be matched. |
---|
true
if the expression matches, otherwise false
.PatternSyntaxException | if the syntax of the supplied regular expression is not valid. |
---|---|
NullPointerException | if expr is null . |
Returns the index within this object that is offset from index
by
codePointOffset
code points.
index | the index within this object to calculate the offset from. |
---|---|
codePointOffset | the number of code points to count. |
IndexOutOfBoundsException | if index is negative or greater than length()
or if there aren't enough code points before or after index to match codePointOffset . |
---|
Compares the specified string to this string and compares the specified range of characters to determine if they are the same.
thisStart | the starting offset in this string. |
---|---|
string | the string to compare. |
start | the starting offset in the specified string. |
length | the number of characters to compare. |
true
if the ranges of characters are equal, false
otherwiseNullPointerException | if string is null .
|
---|
Compares the specified string to this string and compares the specified range of characters to determine if they are the same. When ignoreCase is true, the case of the characters is ignored during the comparison.
ignoreCase | specifies if case should be ignored. |
---|---|
thisStart | the starting offset in this string. |
string | the string to compare. |
start | the starting offset in the specified string. |
length | the number of characters to compare. |
true
if the ranges of characters are equal, false
otherwise.NullPointerException | if string is null .
|
---|
Copies this string replacing occurrences of the specified character with another character.
oldChar | the character to replace. |
---|---|
newChar | the replacement character. |
Copies this string replacing occurrences of the specified target sequence with another sequence. The string is processed from the beginning to the end.
target | the sequence to replace. |
---|---|
replacement | the replacement sequence. |
NullPointerException | if target or replacement is null .
|
---|
Replace any substrings within this string that match the supplied regular
expression expr
, with the string substitute
.
expr | the regular expression to match. |
---|---|
substitute | the string to replace the matching substring with. |
PatternSyntaxException | if the syntax of the supplied regular expression is not valid. |
---|
Replace the first substring within this string that matches the supplied
regular expression expr
, with the string substitute
.
expr | the regular expression to match. |
---|---|
substitute | the string to replace the matching substring with. |
PatternSyntaxException | if the syntax of the supplied regular expression is not valid. |
---|---|
NullPointerException | if strbuf is null . |
Splits this string using the supplied regular expression expr
.
The parameter max
controls the behavior how many times the
pattern is applied to the string.
expr | the regular expression used to divide the string. |
---|---|
max | the number of entries in the resulting array. |
NullPointerException | if expr is null . |
---|---|
PatternSyntaxException | if the syntax of the supplied regular expression is not valid. |
Splits this string using the supplied regular expression expr
.
expr | the regular expression used to divide the string. |
---|
NullPointerException | if expr is null . |
---|---|
PatternSyntaxException | if the syntax of the supplied regular expression is not valid. |
Compares the specified string to this string, starting at the specified offset, to determine if the specified string is a prefix.
prefix | the string to look for. |
---|---|
start | the starting offset. |
true
if the specified string occurs in this string at the
specified offset, false
otherwise.NullPointerException | if prefix is null .
|
---|
Compares the specified string to this string to determine if the specified string is a prefix.
prefix | the string to look for. |
---|
true
if the specified string is a prefix of this string,
false
otherwiseNullPointerException | if prefix is null .
|
---|
Has the same result as the substring function, but is present so that string may implement the CharSequence interface.
start | the offset the first character. |
---|---|
end | the offset of one past the last character to include. |
IndexOutOfBoundsException | if start < 0 , end < 0 , start > end or
end > length() . |
---|
Copies a range of characters into a new string.
start | the offset of the first character. |
---|---|
end | the offset one past the last character. |
IndexOutOfBoundsException | if start < 0 , start > end or end >
length() .
|
---|
Copies a range of characters into a new string.
start | the offset of the first character. |
---|
IndexOutOfBoundsException | if start < 0 or start > length() .
|
---|
Copies the characters in this string to a character array.
Converts this string to lowercase, using the rules of the specified locale.
Most case mappings are unaffected by the language of a Locale
. Exceptions include
dotted and dotless I in Azeri and Turkish locales, and dotted and dotless I and J in
Lithuanian locales. On the other hand, it isn't necessary to provide, a Greek locale to get
correct case mapping of Greek characters: any locale will do.
See http://www.unicode.org/Public/UNIDATA/SpecialCasing.txt for full details of context- and language-specific special cases.
locale | the Locale to use. |
---|
this
if it's already all-lowercase.
Converts this string to lowercase, using the rules of the default locale.
this
if it's already all-lowercase.
Converts the characters in this string to uppercase, using the specified Locale.
locale | the Locale to use. |
---|
Converts the characters in this string to uppercase, using the default Locale.
Copies this string removing white space characters from the beginning and end of the string.
<= \\u0020
removed from
the beginning and the end.
Converts the specified float to its string representation.
value | the float. |
---|
Converts the specified boolean to its string representation. When the
boolean is true
return "true"
, otherwise return "false"
.
value | the boolean. |
---|
Converts the specified double to its string representation.
value | the double. |
---|
Converts the specified character to its string representation.
value | the character. |
---|
Creates a new string containing the characters in the specified character array. Modifying the character array after creating the string has no effect on the string.
data | the array of characters. |
---|
NullPointerException | if data is null .
|
---|
Creates a new string containing the specified characters in the character array. Modifying the character array after creating the string has no effect on the string.
data | the array of characters. |
---|---|
start | the starting offset in the character array. |
length | the number of characters to use. |
IndexOutOfBoundsException | if length < 0 , start < 0 or start +
length > data.length |
---|---|
NullPointerException | if data is null .
|
Converts the specified long to its string representation.
value | the long. |
---|
Converts the specified integer to its string representation.
value | the integer. |
---|
Converts the specified object to its string representation. If the object
is null return the string "null"
, otherwise use toString()
to get the string representation.
value | the object. |
---|
"null"
.