public
final
class
String
extends Object
implements
Serializable,
Comparable<String>,
CharSequence
| java.lang.Object | |
| ↳ | java.lang.String |
An immutable sequence of UTF-16 chars.
See Character for details about the relationship between char and
Unicode code points.
See also:
Fields | |
|---|---|
public
static
final
Comparator<String> |
CASE_INSENSITIVE_ORDER
Compares strings using |
Public constructors | |
|---|---|
String()
Creates an empty string. |
|
String(byte[] data)
Converts the byte array to a string using the system's
|
|
String(byte[] data, int high)
This constructor was deprecated
in API level 1.
Use |
|
String(byte[] data, int offset, int byteCount)
Converts a subsequence of the byte array to a string using the system's
|
|
String(byte[] data, int high, int offset, int byteCount)
This constructor was deprecated
in API level 1.
Use |
|
String(byte[] data, int offset, int byteCount, String charsetName)
Converts the byte array to a string using the named charset. |
|
String(byte[] data, String charsetName)
Converts the byte array to a string using the named charset. |
|
String(byte[] data, int offset, int byteCount, Charset charset)
Converts the byte array to a string using the given charset. |
|
String(byte[] data, Charset charset)
Converts the byte array to a String using the given charset. |
|
String(char[] data)
Initializes this string to contain the given |
|
String(char[] data, int offset, int charCount)
Initializes this string to contain the given |
|
String(String toCopy)
Constructs a new string with the same sequence of characters as |
|
String(StringBuffer stringBuffer)
Creates a |
|
String(int[] codePoints, int offset, int count)
Creates a |
|
String(StringBuilder stringBuilder)
Creates a |
|
Public methods | |
|---|---|
char
|
charAt(int index)
Returns the |
int
|
codePointAt(int index)
Returns the Unicode code point at the given |
int
|
codePointBefore(int index)
Returns the Unicode code point that precedes the given |
int
|
codePointCount(int start, int end)
Calculates the number of Unicode code points between |
int
|
compareTo(String string)
Compares this string to the given string. |
int
|
compareToIgnoreCase(String string)
Compares this string to the given string, ignoring case differences. |
String
|
concat(String string)
Concatenates this string and the specified string. |
boolean
|
contains(CharSequence cs)
Returns true if this string contains the |
boolean
|
contentEquals(CharSequence cs)
Returns true if the |
boolean
|
contentEquals(StringBuffer sb)
Returns true if the |
static
String
|
copyValueOf(char[] data, int start, int length)
Creates a new string by copying the given subsequence of the given |
static
String
|
copyValueOf(char[] data)
Creates a new string by copying the given |
boolean
|
endsWith(String suffix)
Compares the specified string to this string to determine if the specified string is a suffix. |
boolean
|
equals(Object other)
Compares the given object to this string and returns true if they are equal. |
boolean
|
equalsIgnoreCase(String string)
Compares the given string to this string ignoring case. |
static
String
|
format(Locale locale, String format, Object... args)
Returns a formatted string, using the supplied format and arguments, localized to the given locale. |
static
String
|
format(String format, Object... args)
Returns a localized formatted string, using the supplied format and arguments, using the user's default locale. |
void
|
getBytes(int start, int end, byte[] data, int index)
This method was deprecated
in API level 1.
Use |
byte[]
|
getBytes(String charsetName)
Returns a new byte array containing the code points of this string encoded using the named charset. |
byte[]
|
getBytes(Charset charset)
Returns a new byte array containing the code points of this string encoded using the given charset. |
byte[]
|
getBytes()
Returns a new byte array containing the code points in this string encoded using the
system's |
void
|
getChars(int start, int end, char[] buffer, int index)
Copies the given subsequence of this string to the given array starting at the given offset. |
int
|
hashCode()
Returns an integer hash code for this object. |
int
|
indexOf(int c)
Returns the first index of the given code point, or -1. |
int
|
indexOf(int c, int start)
Returns the next index of the given code point, or -1. |
int
|
indexOf(String subString, int start)
Returns the next index of the given string in this string, or -1. |
int
|
indexOf(String string)
Returns the first index of the given string, or -1. |
String
|
intern()
Returns an interned string equal to this string. |
boolean
|
isEmpty()
Returns true if the length of this string is 0. |
int
|
lastIndexOf(String string)
Returns the index of the start of the last match for the given string in this string, or -1. |
int
|
lastIndexOf(int c, int start)
Returns the last index of the code point |
int
|
lastIndexOf(int c)
Returns the last index of the code point |
int
|
lastIndexOf(String subString, int start)
Returns the index of the start of the previous match for the given string in this string, or -1. |
int
|
length()
Returns the number of |
boolean
|
matches(String regularExpression)
Tests whether this string matches the given |
int
|
offsetByCodePoints(int index, int codePointOffset)
Returns the index within this object that is offset from |
boolean
|
regionMatches(boolean ignoreCase, int thisStart, String string, int start, int length)
Returns true if the given subsequence of the given string matches this string starting at the given offset. |
boolean
|
regionMatches(int thisStart, String string, int start, int length)
Returns true if the given subsequence of the given string matches this string starting at the given offset. |
String
|
replace(CharSequence target, CharSequence replacement)
Returns a copy of this string after replacing occurrences of |
String
|
replace(char oldChar, char newChar)
Returns a copy of this string after replacing occurrences of the given |
String
|
replaceAll(String regularExpression, String replacement)
Replaces all matches for |
String
|
replaceFirst(String regularExpression, String replacement)
Replaces the first match for |
String[]
|
split(String regularExpression)
Splits this string using the supplied |
String[]
|
split(String regularExpression, int limit)
Splits this string using the supplied |
boolean
|
startsWith(String prefix)
Compares the specified string to this string to determine if the specified string is a prefix. |
boolean
|
startsWith(String prefix, int start)
Compares the specified string to this string, starting at the specified offset, to determine if the specified string is a prefix. |
CharSequence
|
subSequence(int start, int end)
Equivalent to |
String
|
substring(int start)
Returns a string containing a suffix of this string starting at |
String
|
substring(int start, int end)
Returns a string containing the given subsequence of this string. |
char[]
|
toCharArray()
Returns a new |
String
|
toLowerCase(Locale locale)
Converts this string to lower case, using the rules of |
String
|
toLowerCase()
Converts this string to lower case, using the rules of the user's default locale. |
String
|
toString()
Returns this string. |
String
|
toUpperCase(Locale locale)
Converts this this string to upper case, using the rules of |
String
|
toUpperCase()
Converts this this string to upper case, using the rules of the user's default locale. |
String
|
trim()
Returns a string with no code points |
static
String
|
valueOf(long value)
Returns the string representation of the given long. |
static
String
|
valueOf(Object value)
Converts the specified object to its string representation. |
static
String
|
valueOf(char[] data)
Returns a new string containing the same |
static
String
|
valueOf(double value)
Returns the string representation of the given double. |
static
String
|
valueOf(int value)
Returns the string representation of the given int. |
static
String
|
valueOf(float value)
Returns the string representation of the given float. |
static
String
|
valueOf(char[] data, int start, int length)
Returns a new string containing the same |
static
String
|
valueOf(boolean value)
Converts the specified boolean to its string representation. |
static
String
|
valueOf(char value)
Returns a new string of just the given |
Inherited methods | |
|---|---|
java.lang.Object
| |
java.lang.Comparable
| |
java.lang.CharSequence
| |
Comparator<String> CASE_INSENSITIVE_ORDER
Compares strings using compareToIgnoreCase(String).
This is not suitable for case-insensitive string comparison for all locales.
Use a Collator instead.
String (byte[] data)
Converts the byte array to a string using the system's
default charset.
| Parameters | |
|---|---|
data |
byte
|
String (byte[] data,
int high)
This constructor was deprecated
in API level 1.
Use String(byte[]) or String(byte[], String) instead.
Converts the byte array to a string, setting the high byte of every
char to the specified value.
| Parameters | |
|---|---|
data |
byte:
the byte array to convert to a string. |
high |
int:
the high byte to use. |
| Throws | |
|---|---|
NullPointerException |
if data == null. |
String (byte[] data,
int offset,
int byteCount)
Converts a subsequence of the byte array to a string using the system's
default charset.
| Parameters | |
|---|---|
data |
byte
|
offset |
int
|
byteCount |
int
|
| Throws | |
|---|---|
NullPointerException |
if data == null. |
IndexOutOfBoundsException |
if byteCount < 0 || offset < 0 || offset + byteCount > data.length.
|
String (byte[] data,
int high,
int offset,
int byteCount)
This constructor was deprecated
in API level 1.
Use String(byte[], int, int) instead.
Converts the byte array to a string, setting the high byte of every
char to high.
| Parameters | |
|---|---|
data |
byte
|
high |
int
|
offset |
int
|
byteCount |
int
|
| Throws | |
|---|---|
NullPointerException |
if data == null. |
IndexOutOfBoundsException |
if byteCount < 0 || offset < 0 || offset + byteCount > data.length |
String (byte[] data,
int offset,
int byteCount,
String charsetName)
Converts the byte array to a string using the named charset.
The behavior when the bytes cannot be decoded by the named charset
is unspecified. Use CharsetDecoder for more control.
| Parameters | |
|---|---|
data |
byte
|
offset |
int
|
byteCount |
int
|
charsetName |
String
|
| Throws | |
|---|---|
NullPointerException |
if data == null. |
IndexOutOfBoundsException |
if byteCount < 0 || offset < 0 || offset + byteCount > data.length. |
UnsupportedEncodingException |
if the named charset is not supported. |
String (byte[] data,
String charsetName)
Converts the byte array to a string using the named charset.
The behavior when the bytes cannot be decoded by the named charset
is unspecified. Use CharsetDecoder for more control.
| Parameters | |
|---|---|
data |
byte
|
charsetName |
String
|
| Throws | |
|---|---|
NullPointerException |
if data == null. |
UnsupportedEncodingException |
if charsetName is not supported.
|
String (byte[] data,
int offset,
int byteCount,
Charset charset)
Converts the byte array to a string using the given charset.
The behavior when the bytes cannot be decoded by the given charset
is to replace malformed input and unmappable code points with the charset's default
replacement string. Use CharsetDecoder for more control.
| Parameters | |
|---|---|
data |
byte
|
offset |
int
|
byteCount |
int
|
charset |
Charset
|
| Throws | |
|---|---|
IndexOutOfBoundsException |
if byteCount < 0 || offset < 0 || offset + byteCount > data.length |
NullPointerException |
if data == null |
String (byte[] data,
Charset charset)
Converts the byte array to a String using the given charset.
| Parameters | |
|---|---|
data |
byte
|
charset |
Charset
|
| Throws | |
|---|---|
NullPointerException |
if data == null |
String (char[] data)
Initializes this string to contain the given chars.
Modifying the array after creating the string
has no effect on the string.
| Parameters | |
|---|---|
data |
char
|
| Throws | |
|---|---|
NullPointerException |
if data == null
|
String (char[] data,
int offset,
int charCount)
Initializes this string to contain the given chars.
Modifying the array after creating the string
has no effect on the string.
| Parameters | |
|---|---|
data |
char
|
offset |
int
|
charCount |
int
|
| Throws | |
|---|---|
NullPointerException |
if data == null. |
IndexOutOfBoundsException |
if charCount < 0 || offset < 0 || offset + charCount > data.length
|
String (String toCopy)
Constructs a new string with the same sequence of characters as toCopy.
| Parameters | |
|---|---|
toCopy |
String
|
String (StringBuffer stringBuffer)
Creates a String from the contents of the specified
StringBuffer.
| Parameters | |
|---|---|
stringBuffer |
StringBuffer
|
String (int[] codePoints,
int offset,
int count)
Creates a String from the sub-array of Unicode code points.
| Parameters | |
|---|---|
codePoints |
int
|
offset |
int
|
count |
int
|
| Throws | |
|---|---|
NullPointerException |
if codePoints == 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. |
String (StringBuilder stringBuilder)
Creates a String from the contents of the specified StringBuilder.
| Parameters | |
|---|---|
stringBuilder |
StringBuilder
|
| Throws | |
|---|---|
NullPointerException |
if stringBuilder == null. |
char charAt (int index)
Returns the char at index.
| Parameters | |
|---|---|
index |
int
|
| Returns | |
|---|---|
char |
|
| Throws | |
|---|---|
IndexOutOfBoundsException |
if index < 0 or index >= length().
|
int codePointAt (int index)
Returns the Unicode code point at the given index.
| Parameters | |
|---|---|
index |
int
|
| Returns | |
|---|---|
int |
|
| Throws | |
|---|---|
IndexOutOfBoundsException |
if index < 0 || index >= length() |
See also:
int codePointBefore (int index)
Returns the Unicode code point that precedes the given index.
| Parameters | |
|---|---|
index |
int
|
| Returns | |
|---|---|
int |
|
| Throws | |
|---|---|
IndexOutOfBoundsException |
if index < 1 || index > length() |
See also:
int codePointCount (int start,
int end)
Calculates the number of Unicode code points between start
and end.
| Parameters | |
|---|---|
start |
int:
the inclusive beginning index of the subsequence. |
end |
int:
the exclusive end index of the subsequence. |
| Returns | |
|---|---|
int |
the number of Unicode code points in the subsequence. |
| Throws | |
|---|---|
IndexOutOfBoundsException |
if start < 0 || end > length() || start > end |
See also:
int compareTo (String string)
Compares this string to the given string.
The strings are compared one char at a time.
In the discussion of the return value below, note that char does not
mean code point, though this should only be visible for surrogate pairs.
If there is an index at which the two strings differ, the result is
the difference between the two chars at the lowest such index.
If not, but the lengths of the strings differ, the result is the difference
between the two strings' lengths.
If the strings are the same length and every char is the same, the result is 0.
| Parameters | |
|---|---|
string |
String
|
| Returns | |
|---|---|
int |
|
| Throws | |
|---|---|
NullPointerException |
if string is null.
|
int compareToIgnoreCase (String string)
Compares this string to the given string, ignoring case differences.
The strings are compared one char at a time. This is not suitable
for case-insensitive string comparison for all locales.
Use a Collator instead.
If there is an index at which the two strings differ, the result is
the difference between the two chars at the lowest such index.
If not, but the lengths of the strings differ, the result is the difference
between the two strings' lengths.
If the strings are the same length and every char is the same, the result is 0.
| Parameters | |
|---|---|
string |
String
|
| Returns | |
|---|---|
int |
|
| Throws | |
|---|---|
NullPointerException |
if string is null.
|
String concat (String string)
Concatenates this string and the specified string.
| Parameters | |
|---|---|
string |
String:
the string to concatenate |
| Returns | |
|---|---|
String |
a new string which is the concatenation of this string and the specified string. |
boolean contains (CharSequence cs)
Returns true if this string contains the charss from the given CharSequence.
| Parameters | |
|---|---|
cs |
CharSequence
|
| Returns | |
|---|---|
boolean |
|
boolean contentEquals (CharSequence cs)
Returns true if the chars in the given CharSequence are the same
as those in this string.
| Parameters | |
|---|---|
cs |
CharSequence
|
| Returns | |
|---|---|
boolean |
|
boolean contentEquals (StringBuffer sb)
Returns true if the chars in the given StringBuffer are the same
as those in this string.
| Parameters | |
|---|---|
sb |
StringBuffer
|
| Returns | |
|---|---|
boolean |
|
| Throws | |
|---|---|
NullPointerException |
if sb is null. |
String copyValueOf (char[] data, int start, int length)
Creates a new string by copying the given subsequence of the given char[].
Modifying the array after creating the string has no
effect on the string.
| Parameters | |
|---|---|
data |
char
|
start |
int
|
length |
int
|
| Returns | |
|---|---|
String |
|
| Throws | |
|---|---|
NullPointerException |
if data is null. |
IndexOutOfBoundsException |
if length < 0, start < 0 or start + length >
data.length.
|
String copyValueOf (char[] data)
Creates a new string by copying the given char[].
Modifying the array after creating the string has no
effect on the string.
| Parameters | |
|---|---|
data |
char
|
| Returns | |
|---|---|
String |
|
| Throws | |
|---|---|
NullPointerException |
if data is null.
|
boolean endsWith (String suffix)
Compares the specified string to this string to determine if the specified string is a suffix.
| Parameters | |
|---|---|
suffix |
String
|
| Returns | |
|---|---|
boolean |
|
| Throws | |
|---|---|
NullPointerException |
if suffix is null.
|
boolean equals (Object other)
Compares the given object to this string and returns true if they are
equal. The object must be an instance of String with the same length,
where for every index, charAt on each string returns the same value.
| Parameters | |
|---|---|
other |
Object:
the object to compare this instance with. |
| Returns | |
|---|---|
boolean |
true if the specified object is equal to this Object; false otherwise. |
boolean equalsIgnoreCase (String string)
Compares the given string to this string ignoring case.
The strings are compared one char at a time. This is not suitable
for case-insensitive string comparison for all locales.
Use a Collator instead.
| Parameters | |
|---|---|
string |
String
|
| Returns | |
|---|---|
boolean |
|
String format (Locale locale, String format, Object... args)
Returns a formatted string, using the supplied format and arguments, localized to the given locale.
| Parameters | |
|---|---|
locale |
Locale:
the locale to apply; null value means no localization. |
format |
String:
the format string (see format(String, Object...)) |
args |
Object:
the list of arguments passed to the formatter. If there are
more arguments than required by format,
additional arguments are ignored. |
| Returns | |
|---|---|
String |
the formatted string. |
| Throws | |
|---|---|
NullPointerException |
if format == null |
IllegalFormatException |
if the format is invalid. |
String format (String format, Object... args)
Returns a localized formatted string, using the supplied format and arguments, using the user's default locale.
If you're formatting a string other than for human
consumption, you should use the format(Locale, String, Object...)
overload and supply Locale.US. See
"Be wary of the default locale".
| Parameters | |
|---|---|
format |
String:
the format string (see format(String, Object...)) |
args |
Object:
the list of arguments passed to the formatter. If there are
more arguments than required by format,
additional arguments are ignored. |
| Returns | |
|---|---|
String |
the formatted string. |
| Throws | |
|---|---|
NullPointerException |
if format == null |
IllegalFormatException |
if the format is invalid. |
void getBytes (int start,
int end,
byte[] data,
int index)
This method was deprecated
in API level 1.
Use getBytes() or getBytes(String)
Mangles a subsequence of this string into a byte array by stripping the high order bits from
each char. Use getBytes() or getBytes(String) instead.
| Parameters | |
|---|---|
start |
int:
the start offset in this string. |
end |
int:
the end+1 offset in this string. |
data |
byte:
the destination byte array. |
index |
int:
the start offset in the destination byte array. |
| Throws | |
|---|---|
NullPointerException |
if data is null. |
IndexOutOfBoundsException |
if start < 0, end > length(), index <
0 or end - start > data.length - index. |
byte[] getBytes (String charsetName)
Returns a new byte array containing the code points of this string encoded using the named charset.
The behavior when this string cannot be represented in the named charset
is unspecified. Use CharsetEncoder for more control.
| Parameters | |
|---|---|
charsetName |
String
|
| Returns | |
|---|---|
byte[] |
|
| Throws | |
|---|---|
UnsupportedEncodingException |
if the charset is not supported |
byte[] getBytes (Charset charset)
Returns a new byte array containing the code points of this string encoded using the given charset.
The behavior when this string cannot be represented in the given charset
is to replace malformed input and unmappable code points with the charset's default
replacement byte array. Use CharsetEncoder for more control.
| Parameters | |
|---|---|
charset |
Charset
|
| Returns | |
|---|---|
byte[] |
|
byte[] getBytes ()
Returns a new byte array containing the code points in this string encoded using the
system's default charset.
The behavior when this string cannot be represented in the system's default charset is unspecified. In practice, when the default charset is UTF-8 (as it is on Android), all strings can be encoded.
| Returns | |
|---|---|
byte[] |
|
void getChars (int start,
int end,
char[] buffer,
int index)
Copies the given subsequence of this string to the given array starting at the given offset.
| Parameters | |
|---|---|
start |
int:
the start offset in this string. |
end |
int:
the end+1 offset in this string. |
buffer |
char:
the destination array. |
index |
int:
the start offset in the destination array. |
| Throws | |
|---|---|
NullPointerException |
if buffer is null. |
IndexOutOfBoundsException |
if start < 0, end > length(), start >
end, index < 0, end - start > buffer.length -
index
|
int hashCode ()
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.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode method
if you intend implementing your own hashCode method.
| Returns | |
|---|---|
int |
this object's hash code. |
int indexOf (int c)
Returns the first index of the given code point, or -1. The search starts at the beginning and moves towards the end of this string.
| Parameters | |
|---|---|
c |
int
|
| Returns | |
|---|---|
int |
|
int indexOf (int c,
int start)
Returns the next index of the given code point, or -1. The search starts at the given offset and moves towards the end of this string.
| Parameters | |
|---|---|
c |
int
|
start |
int
|
| Returns | |
|---|---|
int |
|
int indexOf (String subString, int start)
Returns the next index of the given string in this string, or -1. The search for the string starts at the given offset and moves towards the end of this string.
| Parameters | |
|---|---|
subString |
String
|
start |
int
|
| Returns | |
|---|---|
int |
|
| Throws | |
|---|---|
NullPointerException |
if subString is null.
|
int indexOf (String string)
Returns the first index of the given string, or -1. The search starts at the beginning and moves towards the end of this string.
| Parameters | |
|---|---|
string |
String
|
| Returns | |
|---|---|
int |
|
| Throws | |
|---|---|
NullPointerException |
if string is null.
|
String intern ()
Returns an interned string equal to this string. The VM maintains an internal set of
unique strings. All string literals found in loaded classes'
constant pools are automatically interned. Manually-interned strings are only weakly
referenced, so calling intern won't lead to unwanted retention.
Interning is typically used because it guarantees that for interned strings
a and b, a.equals(b) can be simplified to
a == b. (This is not true of non-interned strings.)
Many applications find it simpler and more convenient to use an explicit
HashMap to implement their own pools.
| Returns | |
|---|---|
String |
|
boolean isEmpty ()
Returns true if the length of this string is 0.
| Returns | |
|---|---|
boolean |
|
int lastIndexOf (String string)
Returns the index of the start of the last match for the given string in this string, or -1. The search for the string starts at the end and moves towards the beginning of this string.
| Parameters | |
|---|---|
string |
String
|
| Returns | |
|---|---|
int |
|
| Throws | |
|---|---|
NullPointerException |
if string is null.
|
int lastIndexOf (int c,
int start)
Returns the last index of the code point c, or -1.
The search starts at offset start and moves towards
the beginning of this string.
| Parameters | |
|---|---|
c |
int
|
start |
int
|
| Returns | |
|---|---|
int |
|
int lastIndexOf (int c)
Returns the last index of the code point c, or -1.
The search starts at the end and moves towards the
beginning of this string.
| Parameters | |
|---|---|
c |
int
|
| Returns | |
|---|---|
int |
|
int lastIndexOf (String subString, int start)
Returns the index of the start of the previous match for the given string in this string, or -1. The search for the string starts at the given index and moves towards the beginning of this string.
| Parameters | |
|---|---|
subString |
String
|
start |
int
|
| Returns | |
|---|---|
int |
|
| Throws | |
|---|---|
NullPointerException |
if subString is null.
|
int length ()
Returns the number of chars in this string. If this string contains surrogate pairs,
this is not the same as the number of code points.
| Returns | |
|---|---|
int |
the number of characters. |
boolean matches (String regularExpression)
Tests whether this string matches the given regularExpression. This method returns
true only if the regular expression matches the entire input string. A common mistake is
to assume that this method behaves like contains(CharSequence); if you want to match anywhere
within the input string, you need to add .* to the beginning and end of your
regular expression. See matches(String, CharSequence).
If the same regular expression is to be used for multiple operations, it may be more
efficient to reuse a compiled Pattern.
| Parameters | |
|---|---|
regularExpression |
String
|
| Returns | |
|---|---|
boolean |
|
| Throws | |
|---|---|
|
if the syntax of the supplied regular expression is not valid. |
NullPointerException |
if regularExpression == null |
int offsetByCodePoints (int index,
int codePointOffset)
Returns the index within this object that is offset from index by
codePointOffset code points.
| Parameters | |
|---|---|
index |
int:
the index within this object to calculate the offset from. |
codePointOffset |
int:
the number of code points to count. |
| Returns | |
|---|---|
int |
the index within this object that is the offset. |
| Throws | |
|---|---|
IndexOutOfBoundsException |
if index is negative or greater than length()
or if there aren't enough code points before or after index to match codePointOffset. |
boolean regionMatches (boolean ignoreCase,
int thisStart,
String string,
int start,
int length)
Returns true if the given subsequence of the given string matches this string starting at the given offset.
If ignoreCase is true, case is ignored during the comparison.
The strings are compared one char at a time. This is not suitable
for case-insensitive string comparison for all locales.
Use a Collator instead.
| Parameters | |
|---|---|
ignoreCase |
boolean:
specifies if case should be ignored (use Collator instead for
non-ASCII case insensitivity). |
thisStart |
int:
the start offset in this string. |
string |
String:
the other string. |
start |
int:
the start offset in string. |
length |
int:
the number of chars to compare. |
| Returns | |
|---|---|
boolean |
|
| Throws | |
|---|---|
NullPointerException |
if string is null.
|
boolean regionMatches (int thisStart,
String string,
int start,
int length)
Returns true if the given subsequence of the given string matches this string starting at the given offset.
| Parameters | |
|---|---|
thisStart |
int:
the start offset in this string. |
string |
String:
the other string. |
start |
int:
the start offset in string. |
length |
int:
the number of chars to compare. |
| Returns | |
|---|---|
boolean |
|
| Throws | |
|---|---|
NullPointerException |
if string is null.
|
String replace (CharSequence target, CharSequence replacement)
Returns a copy of this string after replacing occurrences of target replaced
with replacement. The string is processed from the beginning to the
end.
| Parameters | |
|---|---|
target |
CharSequence
|
replacement |
CharSequence
|
| Returns | |
|---|---|
String |
|
| Throws | |
|---|---|
NullPointerException |
if target or replacement is null.
|
String replace (char oldChar, char newChar)
Returns a copy of this string after replacing occurrences of the given char with another.
| Parameters | |
|---|---|
oldChar |
char
|
newChar |
char
|
| Returns | |
|---|---|
String |
|
String replaceAll (String regularExpression, String replacement)
Replaces all matches for regularExpression within this string with the given
replacement.
See Pattern for regular expression syntax.
If the same regular expression is to be used for multiple operations, it may be more
efficient to reuse a compiled Pattern.
| Parameters | |
|---|---|
regularExpression |
String
|
replacement |
String
|
| Returns | |
|---|---|
String |
|
| Throws | |
|---|---|
|
if the syntax of the supplied regular expression is not valid. |
NullPointerException |
if regularExpression == null |
See also:
String replaceFirst (String regularExpression, String replacement)
Replaces the first match for regularExpression within this string with the given
replacement.
See Pattern for regular expression syntax.
If the same regular expression is to be used for multiple operations, it may be more
efficient to reuse a compiled Pattern.
| Parameters | |
|---|---|
regularExpression |
String
|
replacement |
String
|
| Returns | |
|---|---|
String |
|
| Throws | |
|---|---|
|
if the syntax of the supplied regular expression is not valid. |
NullPointerException |
if regularExpression == null |
See also:
String[] split (String regularExpression)
Splits this string using the supplied regularExpression.
Equivalent to split(regularExpression, 0).
See split(CharSequence, int) for an explanation of limit.
See Pattern for regular expression syntax.
If the same regular expression is to be used for multiple operations, it may be more
efficient to reuse a compiled Pattern.
| Parameters | |
|---|---|
regularExpression |
String
|
| Returns | |
|---|---|
String[] |
|
| Throws | |
|---|---|
NullPointerException |
if regularExpression == null |
|
if the syntax of the supplied regular expression is not valid. |
See also:
String[] split (String regularExpression, int limit)
Splits this string using the supplied regularExpression.
See split(CharSequence, int) for an explanation of limit.
See Pattern for regular expression syntax.
If the same regular expression is to be used for multiple operations, it may be more
efficient to reuse a compiled Pattern.
| Parameters | |
|---|---|
regularExpression |
String
|
limit |
int
|
| Returns | |
|---|---|
String[] |
|
| Throws | |
|---|---|
NullPointerException |
if regularExpression == null |
|
if the syntax of the supplied regular expression is not valid. |
boolean startsWith (String prefix)
Compares the specified string to this string to determine if the specified string is a prefix.
| Parameters | |
|---|---|
prefix |
String:
the string to look for. |
| Returns | |
|---|---|
boolean |
true if the specified string is a prefix of this string,
false otherwise |
| Throws | |
|---|---|
NullPointerException |
if prefix is null.
|
boolean startsWith (String prefix, int start)
Compares the specified string to this string, starting at the specified offset, to determine if the specified string is a prefix.
| Parameters | |
|---|---|
prefix |
String:
the string to look for. |
start |
int:
the starting offset. |
| Returns | |
|---|---|
boolean |
true if the specified string occurs in this string at the
specified offset, false otherwise. |
| Throws | |
|---|---|
NullPointerException |
if prefix is null.
|
CharSequence subSequence (int start, int end)
Equivalent to substring(int, int) but needed to implement CharSequence.
| Parameters | |
|---|---|
start |
int:
the start offset of the sub-sequence. It is inclusive, that
is, the index of the first character that is included in the
sub-sequence. |
end |
int:
the end offset of the sub-sequence. It is exclusive, that is,
the index of the first character after those that are included
in the sub-sequence |
| Returns | |
|---|---|
CharSequence |
the requested sub-sequence. |
| Throws | |
|---|---|
IndexOutOfBoundsException |
if start < 0, end < 0, start > end or
end > length(). |
See also:
String substring (int start)
Returns a string containing a suffix of this string starting at start.
The returned string shares this string's backing array.
| Parameters | |
|---|---|
start |
int
|
| Returns | |
|---|---|
String |
|
| Throws | |
|---|---|
IndexOutOfBoundsException |
if start < 0 or start > length().
|
String substring (int start, int end)
Returns a string containing the given subsequence of this string. The returned string shares this string's backing array.
| Parameters | |
|---|---|
start |
int:
the start offset. |
end |
int:
the end+1 offset. |
| Returns | |
|---|---|
String |
|
| Throws | |
|---|---|
IndexOutOfBoundsException |
if start < 0, start > end or end > length().
|
char[] toCharArray ()
Returns a new char array containing a copy of the chars in this string.
This is expensive and rarely useful. If you just want to iterate over the chars in
the string, use charAt(int) instead.
| Returns | |
|---|---|
char[] |
|
String toLowerCase (Locale locale)
Converts this string to lower case, using the rules of 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.
| Parameters | |
|---|---|
locale |
Locale
|
| Returns | |
|---|---|
String |
a new lower case string, or this if it's already all lower case.
|
String toLowerCase ()
Converts this string to lower case, using the rules of the user's default locale. See "Be wary of the default locale".
| Returns | |
|---|---|
String |
a new lower case string, or this if it's already all lower case.
|
String toString ()
Returns this string.
| Returns | |
|---|---|
String |
a printable representation of this object. |
String toUpperCase (Locale locale)
Converts this this string to upper case, using the rules of 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.
| Parameters | |
|---|---|
locale |
Locale
|
| Returns | |
|---|---|
String |
a new upper case string, or this if it's already all upper case.
|
String toUpperCase ()
Converts this this string to upper case, using the rules of the user's default locale. See "Be wary of the default locale".
| Returns | |
|---|---|
String |
a new upper case string, or this if it's already all upper case.
|
String trim ()
Returns a string with no code points <= \\u0020 at
the beginning or end.
| Returns | |
|---|---|
String |
|
String valueOf (long value)
Returns the string representation of the given long.
| Parameters | |
|---|---|
value |
long
|
| Returns | |
|---|---|
String |
|
String valueOf (Object value)
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.
| Parameters | |
|---|---|
value |
Object:
the object. |
| Returns | |
|---|---|
String |
the object converted to a string, or the string "null".
|
String valueOf (char[] data)
Returns a new string containing the same chars as the given
array. Modifying the array after creating the string has no
effect on the string.
| Parameters | |
|---|---|
data |
char
|
| Returns | |
|---|---|
String |
|
| Throws | |
|---|---|
NullPointerException |
if data is null.
|
String valueOf (double value)
Returns the string representation of the given double.
| Parameters | |
|---|---|
value |
double
|
| Returns | |
|---|---|
String |
|
String valueOf (int value)
Returns the string representation of the given int.
| Parameters | |
|---|---|
value |
int
|
| Returns | |
|---|---|
String |
|
String valueOf (float value)
Returns the string representation of the given float.
| Parameters | |
|---|---|
value |
float
|
| Returns | |
|---|---|
String |
|
String valueOf (char[] data, int start, int length)
Returns a new string containing the same chars as the given
subset of the given array. Modifying the array after creating the string has no
effect on the string.
| Parameters | |
|---|---|
data |
char
|
start |
int
|
length |
int
|
| Returns | |
|---|---|
String |
|
| Throws | |
|---|---|
IndexOutOfBoundsException |
if length < 0, start < 0 or start + length > data.length |
NullPointerException |
if data is null.
|
String valueOf (boolean value)
Converts the specified boolean to its string representation. When the
boolean is true return "true", otherwise return "false".
| Parameters | |
|---|---|
value |
boolean:
the boolean. |
| Returns | |
|---|---|
String |
the boolean converted to a string. |
String valueOf (char value)
Returns a new string of just the given char.
| Parameters | |
|---|---|
value |
char
|
| Returns | |
|---|---|
String |
|