Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.lang.String
Field Summary | |
static Comparator |
|
Constructor Summary | |
| |
| |
| |
| |
| |
| |
| |
| |
|
Method Summary | |
char |
|
int |
|
int |
|
int |
|
int | |
int |
|
String | |
boolean |
|
boolean |
|
boolean |
|
static String |
|
static String |
|
boolean | |
boolean | |
boolean |
|
static String | |
static String | |
byte[] |
|
void |
|
byte[] | |
void |
|
int |
|
int |
|
int |
|
int | |
int | |
String |
|
boolean | |
int |
|
int |
|
int |
|
int |
|
int |
|
boolean | |
int |
|
boolean |
|
boolean |
|
String |
|
String |
|
String |
|
String |
|
String[] | |
String[] | |
boolean |
|
boolean |
|
CharSequence |
|
String |
|
String |
|
char[] |
|
String |
|
String |
|
String |
|
String |
|
String |
|
String |
|
static String |
|
static String |
|
static String |
|
static String |
|
static String |
|
static String |
|
static String |
|
static String | |
static String |
|
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public static final ComparatorCASE_INSENSITIVE_ORDER
A Comparator that usesString.compareToIgnoreCase(String)
. This comparator isSerializable
. Note that it ignores Locale, for that, you want a Collator.
- Since:
- 1.2
- See Also:
Collator.compare(String,String)
public String()
Creates an empty String (length 0). Unless you really need a new object, consider using""
instead.
public String(byte[] data)
Creates a new String using the byte array. Uses the encoding of the platform's default charset, so the resulting string may be longer or shorter than the byte array. For more decoding control, useCharsetDecoder
. The behavior is not specified if the decoder encounters invalid characters; this implementation throws an Error.
- Parameters:
data
- byte array to copy
- Throws:
NullPointerException
- if data is null
- Since:
- 1.1
public String(byte[] ascii, int hibyte)
Deprecated. use
String(byte[],String)
to perform correct encodingCreates a new String using an 8-bit array of integer values. Each character c, using corresponding byte b, is created in the new String as if by performing:c = (char) (((hibyte & 0xff) << 8) | (b & 0xff))
- Parameters:
ascii
- array of integer valueshibyte
- top byte of each Unicode character
- Throws:
NullPointerException
- if ascii is null
public String(byte[] data, int offset, int count)
Creates a new String using the portion of the byte array starting at the offset and ending at offset + count. Uses the encoding of the platform's default charset, so the resulting string may be longer or shorter than the byte array. For more decoding control, useCharsetDecoder
. The behavior is not specified if the decoder encounters invalid characters; this implementation throws an Error.
- Parameters:
data
- byte array to copyoffset
- the offset to start atcount
- the number of bytes in the array to use
- Throws:
NullPointerException
- if data is nullIndexOutOfBoundsException
- if offset or count is incorrect
- Since:
- 1.1
- See Also:
String(byte[],int,int,String)
public String(byte[] ascii, int hibyte, int offset, int count)
Deprecated. use
String(byte[],int,int,String)
to perform correct encodingCreates a new String using an 8-bit array of integer values, starting at an offset, and copying up to the count. Each character c, using corresponding byte b, is created in the new String as if by performing:c = (char) (((hibyte & 0xff) << 8) | (b & 0xff))
- Parameters:
ascii
- array of integer valueshibyte
- top byte of each Unicode characteroffset
- position (base 0) to start copying out of asciicount
- the number of characters from ascii to copy
- Throws:
NullPointerException
- if ascii is nullIndexOutOfBoundsException
- if (offset < 0 || count < 0 || offset + count < 0 (overflow) || offset + count > ascii.length) (while unspecified, this is a StringIndexOutOfBoundsException)
public String(byte[] data, int offset, int count, String encoding) throws UnsupportedEncodingException
Creates a new String using the portion of the byte array starting at the offset and ending at offset + count. Uses the specified encoding type to decode the byte array, so the resulting string may be longer or shorter than the byte array. For more decoding control, useCharsetDecoder
, and for valid character sets, seeCharset
. The behavior is not specified if the decoder encounters invalid characters; this implementation throws an Error.
- Parameters:
data
- byte array to copyoffset
- the offset to start atcount
- the number of bytes in the array to useencoding
- the name of the encoding to use
- Throws:
NullPointerException
- if data or encoding is nullIndexOutOfBoundsException
- if offset or count is incorrect (while unspecified, this is a StringIndexOutOfBoundsException)UnsupportedEncodingException
- if encoding is not found
- Since:
- 1.1
public String(byte[] data, String encoding) throws UnsupportedEncodingException
Creates a new String using the byte array. Uses the specified encoding type to decode the byte array, so the resulting string may be longer or shorter than the byte array. For more decoding control, useCharsetDecoder
, and for valid character sets, seeCharset
. The behavior is not specified if the decoder encounters invalid characters; this implementation throws an Error.
- Parameters:
data
- byte array to copyencoding
- the name of the encoding to use
- Throws:
NullPointerException
- if data or encoding is nullUnsupportedEncodingException
- if encoding is not found
- Since:
- 1.1
- See Also:
String(byte[],int,int,String)
public String(char[] data)
Creates a new String using the character sequence of the char array. Subsequent changes to data do not affect the String.
- Parameters:
data
- char array to copy
- Throws:
NullPointerException
- if data is null
public String(char[] data, int offset, int count)
Creates a new String using the character sequence of a subarray of characters. The string starts at offset, and copies count chars. Subsequent changes to data do not affect the String.
- Parameters:
data
- char array to copyoffset
- position (base 0) to start copying out of datacount
- the number of characters from data to copy
- Throws:
NullPointerException
- if data is nullIndexOutOfBoundsException
- if (offset < 0 || count < 0 || offset + count < 0 (overflow) || offset + count > data.length) (while unspecified, this is a StringIndexOutOfBoundsException)
public String(String str)
Copies the contents of a String to a new String. Since Strings are immutable, only a shallow copy is performed.
- Parameters:
str
- String to copy
- Throws:
NullPointerException
- if value is null
public String(StringBuffer buffer)
Creates a new String using the character sequence represented by the StringBuffer. Subsequent changes to buf do not affect the String.
- Parameters:
buffer
- StringBuffer to copy
- Throws:
NullPointerException
- if buffer is null
public String(StringBuilder buffer)
Creates a new String using the character sequence represented by the StringBuilder. Subsequent changes to buf do not affect the String.
- Parameters:
buffer
- StringBuilder to copy
- Throws:
NullPointerException
- if buffer is null
public char charAt(int index)
Returns the character located at the specified index within this String.
- Specified by:
- charAt in interface CharSequence
- Parameters:
index
- position of character to return (base 0)
- Returns:
- character located at position index
- Throws:
IndexOutOfBoundsException
- if index < 0 || index >= length() (while unspecified, this is a StringIndexOutOfBoundsException)
public int codePointAt(int index)
Get the code point at the specified index. This is like #charAt(int), but if the character is the start of a surrogate pair, and the following character completes the pair, then the corresponding supplementary code point is returned.
- Parameters:
index
- the index of the codepoint to get, starting at 0
- Returns:
- the codepoint at the specified index
- Throws:
IndexOutOfBoundsException
- if index is negative or >= length()
- Since:
- 1.5
public int codePointBefore(int index)
Get the code point before the specified index. This is like #codePointAt(int), but checks the characters atindex-1
andindex-2
to see if they form a supplementary code point.
- Parameters:
index
- the index just past the codepoint to get, starting at 0
- Returns:
- the codepoint at the specified index
- Throws:
IndexOutOfBoundsException
- if index is negative or >= length() (while unspecified, this is a StringIndexOutOfBoundsException)
- Since:
- 1.5
public int codePointCount(int start, int end)
Return the number of code points between two indices in theString
. An unpaired surrogate counts as a code point for this purpose. Characters outside the indicated range are not examined, even if the range ends in the middle of a surrogate pair.
- Parameters:
start
- the starting indexend
- one past the ending index
- Returns:
- the number of code points
- Since:
- 1.5
public int compareTo(String anotherString)
Compares this String and another String (case sensitive, lexicographically). The result is less than 0 if this string sorts before the other, 0 if they are equal, and greater than 0 otherwise. After any common starting sequence is skipped, the result isthis.charAt(k) - anotherString.charAt(k)
if both strings have characters remaining, orthis.length() - anotherString.length()
if one string is a subsequence of the other.
- Parameters:
anotherString
- the String to compare against
- Returns:
- the comparison
- Throws:
NullPointerException
- if anotherString is null
public int compareToIgnoreCase(String str)
Compares this String and another String (case insensitive). This comparison is similar to equalsIgnoreCase, in that it ignores locale and multi-characater capitalization, and compares characters after performingCharacter.toLowerCase(Character.toUpperCase(c))
on each character of the string. This is unsatisfactory for locale-based comparison, in which case you should useCollator
.
- Parameters:
str
- the string to compare against
- Returns:
- the comparison
- Since:
- 1.2
- See Also:
Collator.compare(String,String)
public String concat(String str)
Concatenates a String to this String. This results in a new string unless one of the two originals is "".
- Parameters:
str
- String to append to this String
- Returns:
- newly concatenated String
- Throws:
NullPointerException
- if str is null
public boolean contains(CharSequence s)
Returns true iff this String contains the sequence of Characters described in s.
- Parameters:
s
- the CharSequence
- Returns:
- true iff this String contains s
- Since:
- 1.5
public boolean contentEquals(CharSequence seq)
Compares the given CharSequence to this String. This is true if the CharSequence has the same content as this String at this moment.
- Parameters:
seq
- the CharSequence to compare to
- Returns:
- true if CharSequence has the same character sequence
- Throws:
NullPointerException
- if the given CharSequence is null
- Since:
- 1.5
public boolean contentEquals(StringBuffer buffer)
Compares the given StringBuffer to this String. This is true if the StringBuffer has the same content as this String at this moment.
- Parameters:
buffer
- the StringBuffer to compare to
- Returns:
- true if StringBuffer has the same character sequence
- Throws:
NullPointerException
- if the given StringBuffer is null
- Since:
- 1.4
public static String copyValueOf(char[] data)
Returns a String representation of a character array. Subsequent changes to the array do not affect the String.
- Parameters:
data
- the character array
- Returns:
- a String containing the same character sequence as data
- Throws:
NullPointerException
- if data is null
- See Also:
copyValueOf(char[],int,int)
,String(char[])
public static String copyValueOf(char[] data, int offset, int count)
Returns a String representing the character sequence of the char array, starting at the specified offset, and copying chars up to the specified count. Subsequent changes to the array do not affect the String.
- Parameters:
data
- character arrayoffset
- position (base 0) to start copying out of datacount
- the number of characters from data to copy
- Returns:
- String containing the chars from data[offset..offset+count]
- Throws:
NullPointerException
- if data is nullIndexOutOfBoundsException
- if (offset < 0 || count < 0 || offset + count < 0 (overflow) || offset + count > data.length) (while unspecified, this is a StringIndexOutOfBoundsException)
- See Also:
String(char[],int,int)
public boolean endsWith(String suffix)
Predicate which determines if this String ends with a given suffix. If the suffix is an empty String, true is returned.
- Parameters:
suffix
- String to compare
- Returns:
- true if this String ends with the suffix
- Throws:
NullPointerException
- if suffix is null
public boolean equals(Object anObject)
Predicate which compares anObject to this. This is true only for Strings with the same character sequence.
- Parameters:
anObject
- the object to compare
- Returns:
- true if anObject is semantically equal to this
- See Also:
compareTo(String)
,equalsIgnoreCase(String)
public boolean equalsIgnoreCase(String anotherString)
Compares a String to this String, ignoring case. This does not handle multi-character capitalization exceptions; instead the comparison is made on a character-by-character basis, and is true if:
c1 == c2
Character.toUpperCase(c1) == Character.toUpperCase(c2)
Character.toLowerCase(c1) == Character.toLowerCase(c2)
- Parameters:
anotherString
- String to compare to this String
- Returns:
- true if anotherString is equal, ignoring case
public byte[] getBytes()
Converts the Unicode characters in this String to a byte array. Uses the encoding of the platform's default charset, so the result may be longer or shorter than the String. For more encoding control, useCharsetEncoder
. The behavior is not specified if the encoder encounters a problem; this implementation returns null.
- Returns:
- the resulting byte array, or null on a problem
- Since:
- 1.1
public void getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin)
Deprecated. use
getBytes()
, which uses a char to byte encoderCopies the low byte of each character from this String starting at a specified start index, ending at a specified stop index, to a byte array starting at a specified destination begin index.
- Parameters:
srcBegin
- index to being copying characters from this StringsrcEnd
- index after the last character to be copied from this Stringdst
- byte array which each low byte of this String is copied intodstBegin
- index to start writing characters into dst
- Throws:
NullPointerException
- if dst is null and copy length is non-zeroIndexOutOfBoundsException
- if any indices are out of bounds (while unspecified, source problems cause a StringIndexOutOfBoundsException, and dst problems cause an ArrayIndexOutOfBoundsException)
- See Also:
getBytes()
,getBytes(String)
public byte[] getBytes(String enc) throws UnsupportedEncodingException
Converts the Unicode characters in this String to a byte array. Uses the specified encoding method, so the result may be longer or shorter than the String. For more encoding control, useCharsetEncoder
, and for valid character sets, seeCharset
. The behavior is not specified if the encoder encounters a problem; this implementation returns null.
- Parameters:
enc
- encoding name
- Returns:
- the resulting byte array, or null on a problem
- Throws:
NullPointerException
- if enc is nullUnsupportedEncodingException
- if encoding is not supported
- Since:
- 1.1
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
Copies characters from this String starting at a specified start index, ending at a specified stop index, to a character array starting at a specified destination begin index.
- Parameters:
srcBegin
- index to begin copying characters from this StringsrcEnd
- index after the last character to be copied from this Stringdst
- character array which this String is copied intodstBegin
- index to start writing characters into dst
- Throws:
NullPointerException
- if dst is nullIndexOutOfBoundsException
- if any indices are out of bounds (while unspecified, source problems cause a StringIndexOutOfBoundsException, and dst problems cause an ArrayIndexOutOfBoundsException)
public int hashCode()
Computes the hashcode for this String. This is done with int arithmetic, where ** represents exponentiation, by this formula:
s[0]*31**(n-1) + s[1]*31**(n-2) + ... + s[n-1]
.
- Returns:
- hashcode value of this String
public int indexOf(int ch)
Finds the first instance of a character in this String.
- Parameters:
ch
- character to find
- Returns:
- location (base 0) of the character, or -1 if not found
public int indexOf(int ch, int fromIndex)
Finds the first instance of a character in this String, starting at a given index. If starting index is less than 0, the search starts at the beginning of this String. If the starting index is greater than the length of this String, -1 is returned.
- Parameters:
ch
- character to findfromIndex
- index to start the search
- Returns:
- location (base 0) of the character, or -1 if not found
public int indexOf(String str)
Finds the first instance of a String in this String.
- Parameters:
str
- String to find
- Returns:
- location (base 0) of the String, or -1 if not found
- Throws:
NullPointerException
- if str is null
public int indexOf(String str, int fromIndex)
Finds the first instance of a String in this String, starting at a given index. If starting index is less than 0, the search starts at the beginning of this String. If the starting index is greater than the length of this String, -1 is returned.
- Parameters:
str
- String to findfromIndex
- index to start the search
- Returns:
- location (base 0) of the String, or -1 if not found
- Throws:
NullPointerException
- if str is null
public String intern()
Fetches this String from the intern hashtable. If two Strings are considered equal, by the equals() method, then intern() will return the same String instance. ie. if (s1.equals(s2)) then (s1.intern() == s2.intern()). All string literals and string-valued constant expressions are already interned.
- Returns:
- the interned String
public boolean isEmpty()
Returns true if, and only if,length()
is0
.
- Returns:
- true if the length of the string is zero.
- Since:
- 1.6
public int lastIndexOf(int ch)
Finds the last instance of a character in this String.
- Parameters:
ch
- character to find
- Returns:
- location (base 0) of the character, or -1 if not found
public int lastIndexOf(int ch, int fromIndex)
Finds the last instance of a character in this String, starting at a given index. If starting index is greater than the maximum valid index, then the search begins at the end of this String. If the starting index is less than zero, -1 is returned.
- Parameters:
ch
- character to findfromIndex
- index to start the search
- Returns:
- location (base 0) of the character, or -1 if not found
public int lastIndexOf(String str)
Finds the last instance of a String in this String.
- Parameters:
str
- String to find
- Returns:
- location (base 0) of the String, or -1 if not found
- Throws:
NullPointerException
- if str is null
public int lastIndexOf(String str, int fromIndex)
Finds the last instance of a String in this String, starting at a given index. If starting index is greater than the maximum valid index, then the search begins at the end of this String. If the starting index is less than zero, -1 is returned.
- Parameters:
str
- String to findfromIndex
- index to start the search
- Returns:
- location (base 0) of the String, or -1 if not found
- Throws:
NullPointerException
- if str is null
public int length()
Returns the number of characters contained in this String.
- Specified by:
- length in interface CharSequence
- Returns:
- the length of this String
public boolean matches(String regex)
Test if this String matches a regular expression. This is shorthand for.
Pattern
.matches(regex, this)
- Parameters:
regex
- the pattern to match
- Returns:
- true if the pattern matches
- Throws:
NullPointerException
- if regex is nullPatternSyntaxException
- if regex is invalid
- Since:
- 1.4
- See Also:
Pattern.matches(String,CharSequence)
public int offsetByCodePoints(int index, int codePointOffset)
Return the index into this String that is offset from the given index bycodePointOffset
code points.
- Parameters:
index
- the index at which to startcodePointOffset
- the number of code points to offset
- Returns:
- the index into this String that is
codePointOffset
code points offset fromindex
.
- Throws:
IndexOutOfBoundsException
- if index is negative or larger than the length of this string.IndexOutOfBoundsException
- if codePointOffset is positive and the substring starting with index has fewer than codePointOffset code points.IndexOutOfBoundsException
- if codePointOffset is negative and the substring ending with index has fewer than (-codePointOffset) code points.
- Since:
- 1.5
public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)
Predicate which determines if this String matches another String starting at a specified offset for each String and continuing for a specified length, optionally ignoring case. Indices out of bounds are harmless, and give a false result. Case comparisons are based onCharacter.toLowerCase()
andCharacter.toUpperCase()
, not on multi-character capitalization expansions.
- Parameters:
ignoreCase
- true if case should be ignored in comparisiontoffset
- index to start comparison at for this Stringother
- String to compare region to this Stringooffset
- index to start comparison at for otherlen
- number of characters to compare
- Returns:
- true if regions match, false otherwise
- Throws:
NullPointerException
- if other is null
public boolean regionMatches(int toffset, String other, int ooffset, int len)
Predicate which determines if this String matches another String starting at a specified offset for each String and continuing for a specified length. Indices out of bounds are harmless, and give a false result.
- Parameters:
toffset
- index to start comparison at for this Stringother
- String to compare region to this Stringooffset
- index to start comparison at for otherlen
- number of characters to compare
- Returns:
- true if regions match (case sensitive)
- Throws:
NullPointerException
- if other is null
public String replace(char oldChar, char newChar)
Replaces every instance of a character in this String with a new character. If no replacements occur, this is returned.
- Parameters:
oldChar
- the old character to replacenewChar
- the new character
- Returns:
- new String with all instances of oldChar replaced with newChar
public String replace(CharSequence target, CharSequence replacement)
Returns a string that is this string with all instances of the sequence represented bytarget
replaced by the sequence inreplacement
.
- Parameters:
target
- the sequence to be replacedreplacement
- the sequence used as the replacement
- Returns:
- the string constructed as above
public String replaceAll(String regex, String replacement)
Replaces all matching substrings of the regular expression with a given replacement. This is shorthand for.
Pattern
.compile(regex).matcher(this).replaceAll(replacement)
- Parameters:
regex
- the pattern to matchreplacement
- the replacement string
- Returns:
- the modified string
- Throws:
NullPointerException
- if regex or replacement is nullPatternSyntaxException
- if regex is invalid
- Since:
- 1.4
public String replaceFirst(String regex, String replacement)
Replaces the first substring match of the regular expression with a given replacement. This is shorthand for.
Pattern
.compile(regex).matcher(this).replaceFirst(replacement)
- Parameters:
regex
- the pattern to matchreplacement
- the replacement string
- Returns:
- the modified string
- Throws:
NullPointerException
- if regex or replacement is nullPatternSyntaxException
- if regex is invalid
- Since:
- 1.4
public String[] split(String regex)
Split this string around the matches of a regular expression. Each element of the returned array is the largest block of characters not terminated by the regular expression, in the order the matches are found. The array length is unlimited, and trailing empty entries are discarded, as though callingsplit(regex, 0)
.
- Parameters:
regex
- the pattern to match
- Returns:
- the array of split strings
- Throws:
NullPointerException
- if regex or replacement is nullPatternSyntaxException
- if regex is invalid
- Since:
- 1.4
public String[] split(String regex, int limit)
Split this string around the matches of a regular expression. Each element of the returned array is the largest block of characters not terminated by the regular expression, in the order the matches are found. The limit affects the length of the array. If it is positive, the array will contain at most n elements (n - 1 pattern matches). If negative, the array length is unlimited, but there can be trailing empty entries. if 0, the array length is unlimited, and trailing empty entries are discarded. For example, splitting "boo:and:foo" yields:
This is shorthand for
Regex Limit Result ":" 2 { "boo", "and:foo" } ":" t { "boo", "and", "foo" } ":" -2 { "boo", "and", "foo" } "o" 5 { "b", "", ":and:f", "", "" } "o" -2 { "b", "", ":and:f", "", "" } "o" 0 { "b", "", ":and:f" } .
Pattern
.compile(regex).split(this, limit)
- Parameters:
regex
- the pattern to matchlimit
- the limit threshold
- Returns:
- the array of split strings
- Throws:
NullPointerException
- if regex or replacement is nullPatternSyntaxException
- if regex is invalid
- Since:
- 1.4
public boolean startsWith(String prefix)
Predicate which determines if this String starts with a given prefix. If the prefix is an empty String, true is returned.
- Parameters:
prefix
- String to compare
- Returns:
- true if this String starts with the prefix
- Throws:
NullPointerException
- if prefix is null
- See Also:
startsWith(String,int)
public boolean startsWith(String prefix, int toffset)
Predicate which determines if this String contains the given prefix, beginning comparison at toffset. The result is false if toffset is negative or greater than this.length(), otherwise it is the same asthis.substring(toffset).startsWith(prefix)
.
- Parameters:
prefix
- String to comparetoffset
- offset for this String where comparison starts
- Returns:
- true if this String starts with prefix
- Throws:
NullPointerException
- if prefix is null
public CharSequence subSequence(int begin, int end)
Creates a substring of this String, starting at a specified index and ending at one character before a specified index. This behaves likesubstring(begin, end)
.
- Specified by:
- subSequence in interface CharSequence
- Parameters:
begin
- index to start substring (inclusive, base 0)end
- index to end at (exclusive)
- Returns:
- new String which is a substring of this String
- Throws:
IndexOutOfBoundsException
- if begin < 0 || end > length() || begin > end
- Since:
- 1.4
public String substring(int begin)
Creates a substring of this String, starting at a specified index and ending at the end of this String.
- Parameters:
begin
- index to start substring (base 0)
- Returns:
- new String which is a substring of this String
- Throws:
IndexOutOfBoundsException
- if begin < 0 || begin > length() (while unspecified, this is a StringIndexOutOfBoundsException)
public String substring(int begin, int end)
Creates a substring of this String, starting at a specified index and ending at one character before a specified index.
- Parameters:
begin
- index to start substring (inclusive, base 0)end
- index to end at (exclusive)
- Returns:
- new String which is a substring of this String
- Throws:
IndexOutOfBoundsException
- if begin < 0 || end > length() || begin > end (while unspecified, this is a StringIndexOutOfBoundsException)
public char[] toCharArray()
Copies the contents of this String into a character array. Subsequent changes to the array do not affect the String.
- Returns:
- character array copying the String
public String toLowerCase()
Lowercases this String. This uses Unicode's special case mappings, as applied to the platform's default Locale, so the resulting string may be a different length.
- Returns:
- new lowercased String, or this if no characters were lowercased
- See Also:
toLowerCase(Locale)
,toUpperCase()
public String toLowerCase(Locale locale)
Lowercases this String according to a particular locale. This uses Unicode's special case mappings, as applied to the given Locale, so the resulting string may be a different length.
- Parameters:
- Returns:
- new lowercased String, or this if no characters were lowercased
- Throws:
NullPointerException
- if loc is null
- Since:
- 1.1
- See Also:
toUpperCase(Locale)
public String toString()
Returns this, as it is already a String!
- Specified by:
- toString in interface CharSequence
- Returns:
- this
public String toUpperCase()
Uppercases this String. This uses Unicode's special case mappings, as applied to the platform's default Locale, so the resulting string may be a different length.
- Returns:
- new uppercased String, or this if no characters were uppercased
- See Also:
toUpperCase(Locale)
,toLowerCase()
public String toUpperCase(Locale locale)
Uppercases this String according to a particular locale. This uses Unicode's special case mappings, as applied to the given Locale, so the resulting string may be a different length.
- Parameters:
- Returns:
- new uppercased String, or this if no characters were uppercased
- Throws:
NullPointerException
- if loc is null
- Since:
- 1.1
- See Also:
toLowerCase(Locale)
public String trim()
Trims all characters less than or equal to'\u0020'
(' '
) from the beginning and end of this String. This includes many, but not all, ASCII control characters, and allCharacter.isWhitespace(char)
.
- Returns:
- new trimmed String, or this if nothing trimmed
public static String valueOf(boolean b)
Returns a String representing a boolean.
- Parameters:
b
- the boolean
- Returns:
- "true" if b is true, else "false"
public static String valueOf(char c)
Returns a String representing a character.
- Parameters:
c
- the character
- Returns:
- String containing the single character c
public static String valueOf(char[] data)
Returns a String representation of a character array. Subsequent changes to the array do not affect the String.
- Parameters:
data
- the character array
- Returns:
- a String containing the same character sequence as data
- Throws:
NullPointerException
- if data is null
- See Also:
valueOf(char[],int,int)
,String(char[])
public static String valueOf(char[] data, int offset, int count)
Returns a String representing the character sequence of the char array, starting at the specified offset, and copying chars up to the specified count. Subsequent changes to the array do not affect the String.
- Parameters:
data
- character arrayoffset
- position (base 0) to start copying out of datacount
- the number of characters from data to copy
- Returns:
- String containing the chars from data[offset..offset+count]
- Throws:
NullPointerException
- if data is nullIndexOutOfBoundsException
- if (offset < 0 || count < 0 || offset + count > data.length) (while unspecified, this is a StringIndexOutOfBoundsException)
- See Also:
String(char[],int,int)
public static String valueOf(double d)
Returns a String representing a double.
- Parameters:
d
- the double
- Returns:
- String containing the double
- See Also:
Double.toString(double)
public static String valueOf(float f)
Returns a String representing a float.
- Parameters:
f
- the float
- Returns:
- String containing the float
- See Also:
Float.toString(float)
public static String valueOf(int i)
Returns a String representing an integer.
- Parameters:
i
- the integer
- Returns:
- String containing the integer in base 10
- See Also:
Integer.toString(int)
public static String valueOf(Object obj)
Returns a String representation of an Object. This is "null" if the object is null, otherwise it isobj.toString()
(which can be null).
- Parameters:
obj
- the Object
- Returns:
- the string conversion of obj
public static String valueOf(long l)
Returns a String representing a long.
- Parameters:
l
- the long
- Returns:
- String containing the long in base 10
- See Also:
Long.toString(long)