|
Build 1.1_r1 (from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.String
public final class String
An immutable sequence of characters/code units (chars). 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).
StringBuffer,
StringBuilder,
Charset,
Serialized Form| Nested Class Summary | |
|---|---|
(package private) static class |
String.ConsolePrintStream
An PrintStream used for System.out which performs the correct character conversion for the console, since the console may use a different conversion than the default file.encoding. |
| Field Summary | |
|---|---|
static Comparator<String> |
CASE_INSENSITIVE_ORDER
A comparator ignoring the case of the characters. |
| Constructor Summary | |
|---|---|
String()
Creates an empty string. |
|
String(byte[] data)
Converts the byte array to a string using the default encoding as specified by the file.encoding system property. |
|
String(byte[] data,
int high)
Deprecated. Use String(byte[]) or
String(byte[], String) instead. |
|
String(byte[] data,
int start,
int length)
Converts the byte array to a string using the default encoding as specified by the file.encoding system property. |
|
String(byte[] data,
int high,
int start,
int length)
Deprecated. Use String(byte[], int, int) instead. |
|
String(byte[] data,
int start,
int length,
String encoding)
Converts the byte array to a string using the specified encoding. |
|
String(byte[] data,
String encoding)
Converts the byte array to a string using the specified encoding. |
|
String(char[] data)
Initializes this string to contain the characters in the specified character array. |
|
String(char[] data,
int start,
int length)
Initializes this string to contain the specified characters in the character array. |
|
String(int[] codePoints,
int offset,
int count)
Creates a String from the sub-array of Unicode code points. |
|
String(int start,
int length,
char[] data)
|
|
String(String string)
Creates a String that is a copy of the specified string. |
|
String(StringBuffer stringbuffer)
Creates a String from the contents of the specified
StringBuffer. |
|
String(StringBuilder sb)
Creates a String from the contents of the specified StringBuilder. |
|
| Method Summary | |
|---|---|
(package private) void |
_getChars(int start,
int end,
char[] buffer,
int index)
Version of getChars without bounds checks, for use by other classes within the java.lang package only. |
char |
charAt(int index)
Returns the character at the specified offset in this string. |
int |
codePointAt(int index)
Retrieves the Unicode code point (character) value at the specified index. |
int |
codePointBefore(int index)
Retrieves the Unicode code point value that precedes the specified index. |
int |
codePointCount(int beginIndex,
int endIndex)
Calculates the number of Unicode code points between beginIndex
and endIndex. |
int |
compareTo(String string)
Compares the specified string to this string using the Unicode values of the characters. |
int |
compareToIgnoreCase(String string)
Compares the specified string to this string using the Unicode values of the characters, ignoring case differences. |
String |
concat(String string)
Concatenates this string and the specified string. |
boolean |
contains(CharSequence cs)
Determines if this String contains the sequence of characters in
the CharSequence passed. |
boolean |
contentEquals(CharSequence cs)
Compares a CharSequence to this String to determine if
their contents are equal. |
boolean |
contentEquals(StringBuffer strbuf)
Returns whether the characters in the StringBuffer strbuf are the
same as those in this string. |
static String |
copyValueOf(char[] data)
Creates a new string containing the characters in the specified character array. |
static String |
copyValueOf(char[] data,
int start,
int length)
Creates a new string containing the specified characters in the character array. |
boolean |
endsWith(String suffix)
Compares the specified string to this string to determine if the specified string is a suffix. |
boolean |
equals(Object object)
Compares the specified object to this string and returns true if they are equal. |
boolean |
equalsIgnoreCase(String string)
Compares the specified string to this string ignoring the case of the characters and returns true if they are equal. |
static String |
format(Locale loc,
String format,
Object... args)
Returns a formatted string, using the supplied format and arguments, accordingly to the specified locale. |
static String |
format(String format,
Object... args)
Returns a formatted string, using the supplied format and arguments, using the default locale. |
byte[] |
getBytes()
Converts this string to a byte array using the default encoding as specified by the file.encoding system property. |
void |
getBytes(int start,
int end,
byte[] data,
int index)
Deprecated. Use getBytes() or getBytes(String) |
byte[] |
getBytes(String encoding)
Converts this string to a byte array using the specified encoding. |
void |
getChars(int start,
int end,
char[] buffer,
int index)
Copies the specified characters in this string to the character array starting at the specified offset in the character array. |
(package private) char[] |
getValue()
|
int |
hashCode()
Returns an integer hash code for this object. |
int |
indexOf(int c)
Searches in this string for the first index of the specified character. |
int |
indexOf(int c,
int start)
Searches in this string for the index of the specified character. |
int |
indexOf(String string)
Searches in this string for the first index of the specified string. |
int |
indexOf(String subString,
int start)
Searches in this string for the index of the specified string. |
String |
intern()
Searches an internal table of strings for a string equal to this string. |
int |
lastIndexOf(int c)
Searches in this string for the last index of the specified character. |
int |
lastIndexOf(int c,
int start)
Searches in this string for the index of the specified character. |
int |
lastIndexOf(String string)
Searches in this string for the last index of the specified string. |
int |
lastIndexOf(String subString,
int start)
Searches in this string for the index of the specified string. |
int |
length()
Returns the size of this string. |
boolean |
matches(String expr)
Determines whether this string matches a given regular expression. |
int |
offsetByCodePoints(int index,
int codePointOffset)
Returns the index within this object that is offset from index by
codePointOffset code points. |
boolean |
regionMatches(boolean ignoreCase,
int thisStart,
String string,
int start,
int length)
Compares the specified string to this string and compares the specified range of characters to determine if they are the same. |
boolean |
regionMatches(int thisStart,
String string,
int start,
int length)
Compares the specified string to this string and compares the specified range of characters to determine if they are the same. |
String |
replace(char oldChar,
char newChar)
Copies this string replacing occurrences of the specified character with another character. |
String |
replace(CharSequence target,
CharSequence replacement)
Copies this string replacing occurrences of the specified target sequence with another sequence. |
String |
replaceAll(String expr,
String substitute)
Replace any substrings within this string that match the supplied regular expression expr, with the string substitute. |
String |
replaceFirst(String expr,
String substitute)
Replace the first substring within this string that matches the supplied regular expression expr, with the string substitute. |
String[] |
split(String expr)
Splits this string using the supplied regular expression expr. |
String[] |
split(String expr,
int max)
Splits this string using the supplied regular expression expr. |
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)
Has the same result as the substring function, but is present so that string may implement the CharSequence interface. |
String |
substring(int start)
Copies a range of characters into a new string. |
String |
substring(int start,
int end)
Copies a range of characters into a new string. |
char[] |
toCharArray()
Copies the characters in this string to a character array. |
String |
toLowerCase()
Converts the characters in this string to lowercase, using the default Locale. |
String |
toLowerCase(Locale locale)
Converts the characters in this string to lowercase, using the specified Locale. |
String |
toString()
Returns this string. |
String |
toUpperCase()
Converts the characters in this string to uppercase, using the default Locale. |
String |
toUpperCase(Locale locale)
Converts the characters in this string to uppercase, using the specified Locale. |
String |
trim()
Copies this string removing white space characters from the beginning and end of the string. |
static String |
valueOf(boolean value)
Converts the specified boolean to its string representation. |
static String |
valueOf(char value)
Converts the specified character to its string representation. |
static String |
valueOf(char[] data)
Creates a new string containing the characters in the specified character array. |
static String |
valueOf(char[] data,
int start,
int length)
Creates a new string containing the specified characters in the character array. |
static String |
valueOf(double value)
Converts the specified double to its string representation. |
static String |
valueOf(float value)
Converts the specified float to its string representation. |
static String |
valueOf(int value)
Converts the specified integer to its string representation. |
static String |
valueOf(long value)
Converts the specified long to its string representation. |
static String |
valueOf(Object value)
Converts the specified object to its string representation. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final Comparator<String> CASE_INSENSITIVE_ORDER
| Constructor Detail |
|---|
public String()
public String(byte[] data)
data - the byte array to convert to a string.
@Deprecated
public String(byte[] data,
int high)
String(byte[]) or
String(byte[], String) instead.
data - the byte array to convert to a string.high - the high byte to use.
public String(byte[] data,
int start,
int length)
data - the byte array to convert to a string.start - the starting offset in the byte array.length - the number of bytes to convert.
IndexOutOfBoundsException - if length < 0, start < 0 or start + length >
data.length.
@Deprecated
public String(byte[] data,
int high,
int start,
int length)
String(byte[], int, int) instead.
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.
IndexOutOfBoundsException - if length < 0, start < 0 or
start + length > data.length
public String(byte[] data,
int start,
int length,
String encoding)
throws UnsupportedEncodingException
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.
IndexOutOfBoundsException - if length < 0, start < 0 or start + length >
data.length.
UnsupportedEncodingException - if encoding is not supported.
public String(byte[] data,
String encoding)
throws UnsupportedEncodingException
data - the byte array to convert to a string.encoding - the encoding.
UnsupportedEncodingException - if encoding is not supported.public String(char[] data)
data - the array of characters.
public String(char[] data,
int start,
int length)
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
String(int start,
int length,
char[] data)
public String(String string)
String that is a copy of the specified string.
string - the string to copy.public String(StringBuffer stringbuffer)
String from the contents of the specified
StringBuffer.
stringbuffer - the buffer to get the contents from.
public String(int[] codePoints,
int offset,
int count)
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.
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.public String(StringBuilder sb)
String from the contents of the specified StringBuilder.
sb - the StringBuilder to copy the contents from.| Method Detail |
|---|
public char charAt(int index)
charAt in interface CharSequenceindex - the zero-based index in this string.
IndexOutOfBoundsException - if index < 0 or index >= length().public int compareTo(String string)
compareTo in interface Comparable<String>string - the string to compare.
public int compareToIgnoreCase(String string)
string - the string to compare.
public String concat(String string)
string - the string to concatenate
public static String copyValueOf(char[] data)
data - the array of characters.
public static String copyValueOf(char[] data,
int start,
int length)
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.public boolean endsWith(String suffix)
suffix - the suffix to look for.
true if the specified string is a suffix of this string,
false otherwise.public boolean equals(Object object)
equals in class Objectobject - the object to compare.
true if the specified object is equal to this string,
false otherwise.hashCodepublic boolean equalsIgnoreCase(String string)
string - the string to compare.
true if the specified string is equal to this string,
false otherwise.public byte[] getBytes()
@Deprecated
public void getBytes(int start,
int end,
byte[] data,
int index)
getBytes() or getBytes(String)
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.
IndexOutOfBoundsException - if start < 0, end > length(), index <
0 or end - start > data.length - index.
public byte[] getBytes(String encoding)
throws UnsupportedEncodingException
encoding - the encoding to use.
UnsupportedEncodingException - if the encoding is not supported.
public void getChars(int start,
int end,
char[] buffer,
int index)
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.
IndexOutOfBoundsException - if start < 0, end > length(), start >
end, index < 0, end - start > buffer.length -
index
void _getChars(int start,
int end,
char[] buffer,
int index)
public int hashCode()
Objectequals(Object) returns true must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
hashCode in class ObjectObject.equals(java.lang.Object)public int indexOf(int c)
c - the character to find.
public int indexOf(int c,
int start)
c - the character to find.start - the starting offset.
public int indexOf(String string)
string - the string to find.
public int indexOf(String subString,
int start)
subString - the string to find.start - the starting offset.
public String intern()
public int lastIndexOf(int c)
c - the character to find.
public int lastIndexOf(int c,
int start)
c - the character to find.start - the starting offset.
public int lastIndexOf(String string)
string - the string to find.
public int lastIndexOf(String subString,
int start)
subString - the string to find.start - the starting offset.
public int length()
length in interface CharSequence
public boolean regionMatches(int thisStart,
String string,
int start,
int length)
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
public boolean regionMatches(boolean ignoreCase,
int thisStart,
String string,
int start,
int length)
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.
public String replace(char oldChar,
char newChar)
oldChar - the character to replace.newChar - the replacement character.
public String replace(CharSequence target,
CharSequence replacement)
target - the sequence to replace.replacement - the replacement sequence.
public boolean startsWith(String prefix)
prefix - the string to look for.
true if the specified string is a prefix of this string,
false otherwise
public boolean startsWith(String prefix,
int start)
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.public String substring(int start)
start - the offset of the first character.
IndexOutOfBoundsException - if start < 0 or start > length().
public String substring(int start,
int end)
start - the offset of the first character.end - the offset one past the last character.
IndexOutOfBoundsException - if start < 0, start > end or end >
length().public char[] toCharArray()
public String toLowerCase()
public String toLowerCase(Locale locale)
locale - the Locale to use.
public String toString()
toString in interface CharSequencetoString in class Objectpublic String toUpperCase()
public String toUpperCase(Locale locale)
locale - the Locale to use.
public String trim()
<= \\u0020 removed from
the beginning and the end.public static String valueOf(char[] data)
data - the array of characters.
public static String valueOf(char[] data,
int start,
int length)
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.lengthpublic static String valueOf(char value)
value - the character.
public static String valueOf(double value)
value - the double.
public static String valueOf(float value)
value - the float.
public static String valueOf(int value)
value - the integer.
public static String valueOf(long value)
value - the long.
public static String valueOf(Object value)
"null", otherwise use toString() to get the string representation.
value - the object.
"null".public static String valueOf(boolean value)
true return "true", otherwise return "false".
value - the boolean.
public boolean contentEquals(StringBuffer strbuf)
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.public boolean contentEquals(CharSequence cs)
CharSequence to this String to determine if
their contents are equal.
cs - the character sequence to compare to.
true if equal, otherwise falsepublic boolean matches(String expr)
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.
public String replaceAll(String expr,
String substitute)
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.Pattern
public String replaceFirst(String expr,
String substitute)
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.Patternpublic String[] split(String expr)
expr.
expr - the regular expression used to divide the string.
PatternSyntaxException - if the syntax of the supplied regular expression is not
valid.Pattern
public String[] split(String expr,
int max)
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.
PatternSyntaxException - if the syntax of the supplied regular expression is not
valid.Pattern.split(CharSequence, int)
public CharSequence subSequence(int start,
int end)
subSequence in interface CharSequencestart - 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().CharSequence.subSequence(int, int)public int codePointAt(int index)
index.
index - the index to the char code unit within this string.
IndexOutOfBoundsException - if index is negative or greater than or equal to
length().Character.codePointAt(char[], int, int)public int codePointBefore(int index)
index.
index - the index to the char code unit within this string.
IndexOutOfBoundsException - if index is less than 1 or greater than
length().Character.codePointBefore(char[], int, int)
public int codePointCount(int beginIndex,
int endIndex)
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().Character.codePointCount(CharSequence, int, int)public boolean contains(CharSequence cs)
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.
public int offsetByCodePoints(int index,
int codePointOffset)
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.
public static String format(String format,
Object... args)
format - a format string.args - arguments to replace format specifiers (may be none).
IllegalFormatException - if the format is invalid.Formatter
public static String format(Locale loc,
String format,
Object... args)
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).
IllegalFormatException - if the format is invalid.Formatterchar[] getValue()
|
Build 1.1_r1 (from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||