|
![]() |
|||||||||
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
String represents immutable strings of (16-bit) unicode characters.
Supplementary characters are represented by pairs of 16-bit char values (surrogate pairs), i.e., UTF-16 encoding is used. Strings provide access to the single 16-bit char in the UTF-16 string, but also to the unicode code points.
Field Summary | |
---|---|
static Comparator<String> |
CASE_INSENSITIVE_ORDER
A comparator that is based on compareToIgnoreCase to order strings. |
Constructor Summary | |
---|---|
String()
Constructor for an empty string. |
|
String(byte[] bytes)
Constructor that creates a String object from the given byte data using the platform's default encoding. |
|
String(byte[] bytes,
Charset charset)
Constructs a new String by decoding the specified array of
bytes using the specified charset. |
|
String(byte[] value,
int hibyte)
Deprecated. This constructor does not use a proper encoding. Use constructor String(byte[],String) instead. |
|
String(byte[] bytes,
int offset,
int count)
Constructor that creates a String object from the given byte data using the platform's default encoding. |
|
String(byte[] bytes,
int offset,
int length,
Charset charset)
Constructs a new String by decoding the specified subarray of
bytes using the specified charset. |
|
String(byte[] value,
int hibyte,
int offset,
int count)
Deprecated. This constructor does not use a proper encoding. Use constructor String(byte[],int,int,String) instead. |
|
String(byte[] bytes,
int offset,
int count,
String enc)
Create a new String with the contents of the given byte-array converted to 16-bit unicode using the given encoding. |
|
String(byte[] bytes,
String enc)
Create a new String with the contents of the given byte-array converted to 16-bit unicode using the given encoding. |
|
String(char[] value)
Constructor for a string that contains the characters of a given character array. |
|
String(char[] value,
int offset,
int count)
Constructor for a string that contains a subrange of the characters of a given character array. |
|
String(int[] codePoints,
int offset,
int count)
Constructor that creates a string object from the unicode code points in an integer array. |
|
String(String str)
Constructor for a copy of a string. |
|
String(StringBuffer sb)
Constructor that creates a String object from the characters in a StringBuffer. |
|
String(StringBuilder sb)
Constructor that creates a String object from the characters in a StringBuilder. |
Method Summary | |
---|---|
char |
charAt(int index)
charAt returns the 16-bit character at the given index of this String. |
int |
codePointAt(int index)
codePointAt |
int |
codePointBefore(int index)
codePointBefore |
int |
codePointCount(int beginIndex,
int endIndex)
codePointCount |
int |
compareTo(String str)
compareTo compares two strings lexicographically. |
int |
compareToIgnoreCase(String str)
compareTo compares two strings lexicographically ignoring case. |
String |
concat(String str)
concat creates a String that contains the concatenation of this string and another string. |
boolean |
contains(CharSequence s)
Check if this string contains the given CharSequence. |
boolean |
contentEquals(CharSequence cs)
Compares the content of the given CharSequence to this String. |
boolean |
contentEquals(StringBuffer sb)
Compares the content of the given StringBuffer to this String. |
static String |
copyValueOf(char[] data)
copyValueOf returns a String containing the characters of the given character array. |
static String |
copyValueOf(char[] data,
int offset,
int count)
copyValueOf creates a String that contains a subrange of the characters of a given character array. |
boolean |
endsWith(String suffix)
Check if this string ends with the given suffix. |
boolean |
equals(Object o)
Compare this String to another String. |
boolean |
equalsIgnoreCase(String str)
Compare this String to another String ignoring case. |
static String |
format(Locale l,
String format,
Object... args)
Returns a formatted string using the specified locale, format string, and arguments. |
static String |
format(String format,
Object... args)
Returns a formatted string using the specified format string and arguments. |
byte[] |
getBytes()
getBytes converts the characters of this String to a sequence of bytes using the default encoding. |
byte[] |
getBytes(Charset encoding)
Encodes this String into a sequence of bytes using the given
charset, storing the result into a
new byte array. |
void |
getBytes(int srcBegin,
int srcEnd,
byte[] dst,
int dstBegin)
Deprecated. This method does not use the proper encoding. Use getBytes() to use the default encoding. |
byte[] |
getBytes(String encoding)
getBytes converts the characters of this String to a sequence of bytes using the specified encoding. |
void |
getChars(int srcBegin,
int srcEnd,
char[] dst,
int dstBegin)
getChars copies a subrange of the the characters of this string into a character array. |
int |
hashCode()
hashCode calculates a hash code for this string. |
int |
indexOf(int ch)
Find the first index of a given character or code point. |
int |
indexOf(int ch,
int from)
Find the first index of a given character or code point starting from a given findex. |
int |
indexOf(String str)
Return the index of the first substring of this that is equal to str. |
int |
indexOf(String str,
int from)
Return the index of the first substring of this that is equal to str and that start at from or later. |
protected int |
indexOfCharSequence(CharSequence s,
int from)
Return the index of the first occurrence of a substring this that is equal to a CharSequence and that starts at from or later. |
String |
intern()
intern interns this String. |
boolean |
isEmpty()
Returns true if, and only if, length() is 0. |
int |
lastIndexOf(int ch)
Find the last index of a given character or code point. |
int |
lastIndexOf(int ch,
int from)
Find the last index of a given character or code point starting from a given findex. |
int |
lastIndexOf(String str)
Return the index of the last substring of this that is equal to str. |
int |
lastIndexOf(String str,
int from)
Return the index of the last substring of this that is equal to str and that is before a given index. |
int |
length()
length returns the length of this string, i.e., the number of 16-bit characters contained in this string. |
boolean |
matches(String regex)
Test if this String matches the given regular expression. |
int |
offsetByCodePoints(int index,
int codePointOffset)
offsetByCodePoints |
boolean |
regionMatches(boolean ignoreCase,
int offset,
String other,
int ooffset,
int len)
Compare a region of this string with another string, optionally ignoring case. |
boolean |
regionMatches(int offset,
String other,
int ooffset,
int len)
Compare a region of this string with another string. |
String |
replace(char oldChar,
char newChar)
replace creates a new String that is equal to this String with a given character replaced by another character. |
String |
replace(CharSequence target,
CharSequence replacement)
Replaces all occurrences of target in this by te given replacement. |
String |
replaceAll(String regex,
String replacement)
Replaces all occurrences of the substring that matches the given regular expression. |
String |
replaceFirst(String regex,
String replacement)
Replaces the first substring that matches the given reugular expression. |
String[] |
split(String regex)
split splits the string at substrings that match the given regular expression. |
String[] |
split(String regex,
int limit)
split splits the string at substrings that match the given regular expression. |
boolean |
startsWith(String prefix)
Check if this string starts with the given prefix. |
boolean |
startsWith(String prefix,
int offset)
Check if this string starts with the given prefix from the given offset. |
CharSequence |
subSequence(int start,
int end)
subSequence creates a subsequence of this sequence. |
String |
substring(int from)
Create a new String object with the contents of the suffix of this String starting at a given index. |
String |
substring(int from,
int end)
Create a new String objects with the contents of the substring of this String. |
char[] |
toCharArray()
toCharArray allocates a new character array and copies the characters of this String into the array. |
String |
toLowerCase()
toLowerCase converts this String to lower case using the default locale. |
String |
toLowerCase(Locale locale)
toLowerCase converts this String to lower case respecting the given locale. |
String |
toString()
toString creates a printable string that represents this object for debugging purposes. |
String |
toUpperCase()
toUpperCase converts this String to lower case using the default locale. |
String |
toUpperCase(Locale locale)
toLowerCase converts this String to upper case respecting the given locale. |
String |
trim()
trim removes all leading and trailing characters with a code <= ' ' from this String. |
static String |
valueOf(boolean b)
valueOf converts a boolean to a String. |
static String |
valueOf(char c)
valueOf creates a one-character string containing the given character. |
static String |
valueOf(char[] data)
valueOf returns a String containing the characters of the given character array. |
static String |
valueOf(char[] data,
int offset,
int count)
valueOf creates a String that contains a subrange of the characters of a given character array. |
static String |
valueOf(double d)
valueOf converts a double to a String |
static String |
valueOf(float f)
valueOf converts a float to a String |
static String |
valueOf(int i)
valueOf converts an int to a String. |
static String |
valueOf(long l)
valueOf converts a long to a String |
static String |
valueOf(Object obj)
valueOf returns a String created from a given object or null. |
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
This comparator is serializable.
Constructor Detail |
---|
public String()
A more efficient way to obtain an empty string is by using the string constant "". Using this constructor will always create a new instance, i.e., perform a memory allocation.
public String(String str)
Using this constructor will always create a new instance, i.e., perform a memory allocation. Unless a different instance is required, copying of a string is not needed.
str
- string to copy
NullPointerException
- if str is null.public String(char[] value)
ensure
( length() == value.length && for i in 0..value.length-1: charAt(i) == value[i])
value
- character array
NullPointerException
- if value is null.public String(char[] value, int offset, int count)
ensure
( length() == count && for i in 0..count-1: charAt(i) == value[offset+i])
value
- the character arrayoffset
- the index of the first character to use in the
stringcount
- the number of characters to use in the string.
NullPointerException
- if value is null.
IndexOutOfBoundsException
- if count<0 or offset<0 or
offset+count>value.length.@Deprecated public String(byte[] value, int hibyte, int offset, int count)
ensure
( length() == count && for i in 0..count-1: charAt(i) == ((hibyte & 0xff) << 8 + value[offset+i]))
value
- the buffer to read from.hibyte
- fixed hibate for all characters.offset
- the index of the first character in value to use in
the stringcount
- number of bytes to copy over.
NullPointerException
- if value is null
IndexOutOfBoundsException
- if count<0 or offset<0 or
offset+count>value.length.@Deprecated public String(byte[] value, int hibyte)
String(byte[],String)
instead.
ensure
( length() == value.length && for i in 0..length()-1: charAt(i) == ((hibyte & 0xff) << 8 + value[i]))
value
- the buffer to read from.hibyte
- fixed hibate for all characters.
NullPointerException
- if value is nullpublic String(byte[] bytes, int offset, int count, String enc) throws UnsupportedEncodingException
bytes
- the byte array to read fromoffset
- offset of the first byte to used from bytes.count
- number of bytes to use from bytes.enc
- the encoding to be used.
UnsupportedEncodingException
- if the specified encoding is
not supported.
NullPointerException
- if bytes is null or enc is null.
IndexOutOfBoundsException
- if count<0 or offset<0 or
offset+count>value.length.public String(byte[] bytes, int offset, int length, Charset charset)
String
by decoding the specified subarray of
bytes using the specified charset.
The length of the new String
is a function of the charset, and
hence may not be equal to the length of the subarray.
This method always replaces malformed-input and unmappable-character
sequences with this charset's default replacement string. The CharsetDecoder
class should be used when more control
over the decoding process is required.
bytes
- The bytes to be decoded into charactersoffset
- The index of the first byte to decodelength
- The number of bytes to decodecharset
- The charset to be used to
decode the bytes
IndexOutOfBoundsException
- If the offset
and length
arguments index
characters outside the bounds of the bytes
arraypublic String(byte[] bytes, Charset charset)
String
by decoding the specified array of
bytes using the specified charset.
The length of the new String
is a function of the charset, and
hence may not be equal to the length of the byte array.
This method always replaces malformed-input and unmappable-character
sequences with this charset's default replacement string. The CharsetDecoder
class should be used when more control
over the decoding process is required.
bytes
- The bytes to be decoded into characterscharset
- The charset to be used to
decode the bytes
public String(byte[] bytes, String enc) throws UnsupportedEncodingException
bytes
- the byte array to read fromenc
- the encoding to be used.
UnsupportedEncodingException
- if the specified encoding is
not supported.
NullPointerException
- if bytes is null or enc is null.public String(byte[] bytes, int offset, int count)
For JamaicaVM, the default encoding is assumed to be 8-bit ASCII.
bytes
- the byte array to read fromoffset
- the start index in bytescount
- the number of bytes to be used in the new String
NullPointerException
- if bytes is null.
IndexOutOfBoundsException
- if count<0 or offset<0 or
offset+count>bytes.length.public String(byte[] bytes)
For JamaicaVM, the default encoding is assumed to be 8-bit ASCII.
bytes
- the byte array to read from
NullPointerException
- if bytes is null.public String(StringBuffer sb)
ensure
( length() == sb.length() && for i in 0..length()-1: charAt(i) == sb.charAt(i))
sb
- the string buffer to take the characters from
NullPointerException
- if sb is null.public String(StringBuilder sb)
ensure
( length() == sb.length() && for i in 0..length()-1: charAt(i) == sb.charAt(i))
sb
- the string builder to take the characters from
NullPointerException
- if sb is null.public String(int[] codePoints, int offset, int count)
codePoints
- an array of unicode code pointsoffset
- the offset of the first code point to usecount
- the number of code points to use
IllegalArgumentException
- if
codePoints[offset..offset+count] contains invalid code points
NullPointerException
- if codePoints is null.
IndexOutOfBoundsException
- if count<0 or offset<0 or
offset+count>bytes.length.Method Detail |
---|
public int length()
ensure
(result >= 0)
length
in interface CharSequence
public char charAt(int index)
implemented in C for better performance.
charAt
in interface CharSequence
index
- the position of the character to the read
IndexOutOfBoundsException
- if index<0 or index >=
length().public int codePointAt(int index)
index
-
public int codePointBefore(int index)
index
-
public int codePointCount(int beginIndex, int endIndex)
beginIndex
- endIndex
-
public int offsetByCodePoints(int index, int codePointOffset)
index
- codePointOffset
-
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
ensure
(for i in 0..srcEnd-srcBegin-1: charAt(srcBegin+i) == dst[dstBegin+i])
srcBegin
- the index of the first character to copysrcEnd
- the index of the last character to copydst
- (out!) the target character arraydstBegin
- the index in the target array at which the first character should be stored.
IndexOutOfBoundsException
- if srcBegin<0, srcBegin>srcEnd,
srcEnd > length(), dstBegin<0 or dstBegin+srcEnd-srcBegin >
dst.length;
NullPointerException
- if dst is null@Deprecated public void getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin)
ensure
(for i in 0..srcEnd-srcBegin-1: (charAt(srcBegin+i)&0xff) == (dst[dstBegin+i]&0xff))
srcBegin
- the index of the first character to copysrcEnd
- the index of the last character to copydst
- (out!) the target byte arraydstBegin
- the index in the target array at which the first character should be stored.
IndexOutOfBoundsException
- if srcBegin<0, srcBegin>srcEnd,
srcEnd > length(), dstBegin<0 or dstBegin+srcEnd-srcBegin >
dst.length;
NullPointerException
- if dst is nullpublic byte[] getBytes(String encoding) throws UnsupportedEncodingException
Characters that cannot be encoded with the specified encoding will be replaced by '?'.
encoding
- the encoding to be used, null for the default
encoding (ISO 8859-1 for JamaicaVM)
UnsupportedEncodingException
- if the specified encoding is
not supported.public byte[] getBytes()
Characters that cannot be encoded with the default encoding will be replaced by '?'.
For JamaicaVM, the default encoding is ISO 8859-1.
public byte[] getBytes(Charset encoding)
String
into a sequence of bytes using the given
charset, storing the result into a
new byte array.
This method always replaces malformed-input and unmappable-character
sequences with this charset's default replacement byte array. The
CharsetEncoder
class should be used when more
control over the encoding process is required.
encoding
- The Charset to be used to encode
the String
public boolean equals(Object o)
ensure
(result == ( (anObject instanceof String) && (length() == ((String)o).length()) && (for all i in 0..length()-1: charAt(i) == ((String)o).charAt(i)))
implemented in C for better performance.
equals
in class Object
o
- object
public boolean contentEquals(StringBuffer sb)
sb
- the StringBuffer to compare.
NullPointerException
- if sb is nullpublic boolean contentEquals(CharSequence cs)
cs
- the CharSequence to compare with.
NullPointerException
- if cs is nullpublic boolean equalsIgnoreCase(String str)
(c1 == c2) || Character.toUpperCase(c1) == Character.toUpperCase(c2) || Character.toLowerCase(c1) == Character.toLowerCase(c2)
str
- the string to compare to
public int compareTo(String str)
implemented in C for better performance.
compareTo
in interface Comparable<String>
str
- a string to compare to.
NullPointerException
- if str==nullpublic int compareToIgnoreCase(String str)
Case is ignored by converting each character c via nested calls to Character.toLowerCase(Character.toUpperCase(c)) before the comparison.
str
- a string to compare to.
NullPointerException
- if str==nullpublic boolean regionMatches(int offset, String other, int ooffset, int len)
offset
- the index in this at which comparison should start.other
- the other String to compare withooffset
- the index in other at which comparison should
start.len
- the number of characters to compare.
NullPointerException
- if other is null.public boolean regionMatches(boolean ignoreCase, int offset, String other, int ooffset, int len)
(c1 == c2) || Character.toUpperCase(c1) == Character.toUpperCase(c2) || Character.toLowerCase(c1) == Character.toLowerCase(c2)
ignoreCase
- true to ignore case, false to compare
characters directly.offset
- the index in this at which comparison should start.other
- the other String to compare withooffset
- the index in other at which comparison should
start.len
- the number of characters to compare.
NullPointerException
- if other is null.public boolean startsWith(String prefix, int offset)
prefix
- the prefixoffset
- the offset in this where to start looking for the prefix
NullPointerException
- if prefix is null.public boolean startsWith(String prefix)
prefix
- the prefix
NullPointerException
- if prefix is null.public boolean endsWith(String suffix)
suffix
- the suffix
NullPointerException
- if suffix is null.public int hashCode()
charAt(0)*31**(length()-1) + charAt(1)*31**(length()-2) + ... + charAt(length()-1)
implemented in C for better performance.
hashCode
in class Object
public int indexOf(int ch)
ensure
( ((ch <= 0xffff && result == -1) IMPLIES for all i=0..length()-1: charAt(i) != ch) && ((ch <= 0xffff && result != -1) IMPLIES ( (charAt(result) == ch) && for all i=0..result-1: charAt(i) != ch)) && ((ch > 0xffff && result == -1) IMPLIES for all codepoint indices i: codePointAt(i) != ch) && ((ch > 0xffff && result != -1) IMPLIES ( (codePointAt(result) == ch) && for all i=0..result-1: codePointAt(i) != ch)
ch
- the character or code point
public int indexOf(int ch, int from)
ensure
( ((ch <= 0xffff && result == -1) IMPLIES for all i=from..length()-1: charAt(i) != ch) && ((ch <= 0xffff && result != -1) IMPLIES ( (charAt(result) == ch) && for all i=from..result-1: charAt(i) != ch)) && ((ch > 0xffff && result == -1) IMPLIES for all codepoint indices i: codePointAt(i) != ch) && ((ch > 0xffff && result != -1) IMPLIES ( (codePointAt(result) == ch) && for all i=from..result-1: codePointAt(i) != ch)
ch
- the character or code point
public int lastIndexOf(int ch)
ensure
( ((ch <= 0xffff && result == -1) IMPLIES for all i=0..length()-1: charAt(i) != ch) && ((ch <= 0xffff && result != -1) IMPLIES ( (charAt(result) == ch) && for all i=result+1..length()-1: charAt(i) != ch)) && ((ch > 0xffff && result == -1) IMPLIES for all codepoint indices i: codePointAt(i) != ch) && ((ch > 0xffff && result != -1) IMPLIES ( (codePointAt(result) == ch) && for all codepoint indices in i=result+1..length()-1: codePointAt(i) != ch)
ch
- the character or code point
public int lastIndexOf(int ch, int from)
ensure
( ((ch <= 0xffff && result == -1) IMPLIES for all i=0..from: charAt(i) != ch) && ((ch <= 0xffff && result != -1) IMPLIES ( (charAt(result) == ch) && for all i=0..from: charAt(i) != ch)) && ((ch > 0xffff && result == -1) IMPLIES for all codepoint indices i in 0..from: codePointAt(i) != ch) && ((ch > 0xffff && result != -1) IMPLIES ( (codePointAt(result) == ch) && for all i=0..from: codePointAt(i) != ch)
ch
- the character or code point
public int indexOf(String str)
str
- the required substring
NullPointerException
- if str is null.public int indexOf(String str, int from)
ensure
(result != -1 IMPLIES startWith(str,result));
implemented in C for better performance.
str
- the required substringfrom
- the index to start to search for the substring.
NullPointerException
- if str is null.public int lastIndexOf(String str)
ensure
(result != -1 IMPLIES startsWith(str,result) && result <= length());
str
- the required substring
NullPointerException
- if str is null.public int lastIndexOf(String str, int from)
ensure
(result != -1 IMPLIES startsWith(str,result) && result <= from && result <= length());
str
- the required substringfrom
- the starting index.
NullPointerException
- if str is null.public String substring(int from)
ensure
( (result.length() == length()-from) && (for all i=0..result.length(): result.charAt(i) == charAt(from+i)));
from
- the starting index.
IndexOutOfBoundsException
- if from<0 or from>length().public String substring(int from, int end)
ensure
( (result.length() == end-from) && (for all i=0..result.length(): result.charAt(i) == charAt(from+i)));
from
- the starting index (inclusive).end
- the end index (exclusive)..
IndexOutOfBoundsException
- if from<0 or end>length() or
endpublic CharSequence subSequence(int start, int end)
This implementation of the interface method CharSequence.subSequence behaves exactly as substring(start,end).
subSequence
in interface CharSequence
start
- the start position.end
- the end position.
IndexOutOfBoundsException
- if start<0 || endpublic boolean contains(CharSequence s)
s
- a character sequence
NullPointerException
- if s is nullprotected int indexOfCharSequence(CharSequence s, int from)
ensure
(result != -1 IMPLIES startsWith(s.toString(),result));
s
- the required substringfrom
- the index to start to search for the substring.
NullPointerException
- if s is null.public String replace(CharSequence target, CharSequence replacement)
target
- the strings to replacereplacement
- the string target should be replaced with
NullPointerException
- if target or replacement is null.public String concat(String str)
For JamaicaVM, this returns this or str if str.length()==0 or this.length()==0, respectively.
ensure
( (result.length() == this.length()+str.length()) && (for all i=0..this.length(): result.charAt(i ) == charAt(i)) && (for all i=0..str .length(): result.charAt(length()+i) == str.charAt(i)))
str
- the other string
NullPointerException
- if str is nullpublic String replace(char oldChar, char newChar)
ensure
( (result.length() == length()) && (for all i=0..length()-1: result.charAt(i) == (charAt(i)==oldChar ? newChar: charAt(i))))
oldChar
- the character to be replacednewChar
- the character oldChar is to be replaced with
public boolean matches(String regex)
This method behaves exactly as Pattern.matches(regex,this).
regex
- regular expression to match.
PatternSyntaxException
- if the syntax of regex is invalid.public String replaceFirst(String regex, String replacement)
This method behaves exactly as
Pattern.compile(regex).matcher(this).replaceFirst(replacement)
regex
- regular expression to match.replacement
- replacement string for the matched substring.
PatternSyntaxException
- if the syntax of regex is invalid.public String replaceAll(String regex, String replacement)
This method behaves exactly as
Pattern.compile(regex).matcher(this).replaceAll(replacement)
regex
- regular expression to match.replacement
- replacement string for the matched substring.
PatternSyntaxException
- if the syntax of regex is invalid.public String[] split(String regex, int limit)
The limit parameter controls the spliting process:
limit > 0 the array will have max limit entries and the last entry will contain the left over string after regex was applied (limit-1) times. limit == 0 regex will be applied as often as possible and trailing empty strings are discarted. limit < 0 regex will be applied as often as possible and trailing empty strings are *not* discarted.
This method behaves exactly as
Pattern.compile(regex).split(this,limit);
regex
- regular expression of the delimter substring.limit
- index for the split operation.
PatternSyntaxException
- if the syntax of regex is invalid.public String[] split(String regex)
This method behaves exactly as a call to split(regex,0).
regex
- regular expression of the delimter substring.
PatternSyntaxException
- if the syntax of regex is invalid.public String toLowerCase(Locale locale)
locale
- the locale
NullPointerException
- if locale is nullpublic String toLowerCase()
This is equivalent to toLowerCase(Locale.getDefault()).
public String toUpperCase(Locale locale)
locale
- the locale
NullPointerException
- if locale is nullpublic String toUpperCase()
This is equivalent to toUpperCase(Locale.getDefault()).
public String trim()
public String toString()
toString
in interface CharSequence
toString
in class Object
public char[] toCharArray()
ensure
( result.length == length() && (for all i=0..length()-1: result[i] == charAt(i)))
public static String valueOf(Object obj)
obj
- an object or null
public static String valueOf(char[] data)
ensure
( result.length() == data.length && for i in 0..data.length-1: result.charAt(i) == data[i])
data
- the character array
NullPointerException
- if data is nullpublic static String copyValueOf(char[] data)
ensure
( result.length() == data.length && for i in 0..data.length-1: result.charAt(i) == data[i])
This is equivalent to valueOf(data)
data
- the character array
NullPointerException
- if data is nullpublic static String valueOf(char[] data, int offset, int count)
ensure
( result.length() == count && for i in 0..count-1: result.charAt(i) == data[offset+i])
data
- the character arrayoffset
- the index of the first character to use in the
stringcount
- the number of characters to use in the string.
NullPointerException
- if data is null.
IndexOutOfBoundsException
- if count<0 or offset<0 or
offset+count>data.length.public static String copyValueOf(char[] data, int offset, int count)
ensure
( result.length() == count && for i in 0..count-1: result.charAt(i) == data[offset+i])
This is equivalent to valueOf(data,offset,count)
data
- the character arrayoffset
- the index of the first character to use in the
stringcount
- the number of characters to use in the string.
NullPointerException
- if data is null.
IndexOutOfBoundsException
- if count<0 or offset<0 or
offset+count>data.length.public static String valueOf(boolean b)
b
- the boolean value
public static String valueOf(char c)
A cache is used to avoid redundant allocations of the same string.
ensure
( result.length() == 1 && result.charAt(0) == c);
c
- the character
public static String valueOf(int i)
i
- an integer
public static String valueOf(long l)
l
- a long
public static String valueOf(float f)
f
- a float
public static String valueOf(double d)
d
- a double
public String intern()
s1.equals(s2) <==> s1.intern() == s2.intern()
Note that String constants (such as "Hello") are automatically interned by the virtual machine, such that the following holds:
s.equals("const string") <==> s.intern() == "const string"
intern() may be used for more efficient String equality comparison and to safe memory if many equal Strings are in use simulteneously.
However, intern() requires additional memory for each intern()ed String, such that this function should not be used without reason.
intern()ed Strings that become unused by the application will be reclaimed using weak references when the system memory runs low.
For JamaicaVM: intern() needs to allocate memory on the heap. If
this function is called from within RTSJ's scoped memory (ScopedMemory
), this method will anyway perform an
allocation on the heap for the resulting intern()ed String. The
resulting String will have its MemoryArea
set to ImmortalMemory
such that intern()ed
Strings can be used even by code that cannot access heap objects
(such as NoHeapRealtimeThread
). However,
the memory for intern()ed strings will be reclaimed after the
last reference to such a string is deleted.
public static String format(String format, Object... args)
The locale always used is the one returned by Locale.getDefault()
.
format
- A format stringargs
- Arguments referenced by the format specifiers in the format
string. If there are more arguments than format specifiers, the
extra arguments are ignored. The number of arguments is
variable and may be zero. The maximum number of arguments is
limited by the maximum dimension of a Java array as defined by
the Java
Virtual Machine Specification. The behaviour on a
null argument depends on the conversion.
IllegalFormatException
- If a format string contains an illegal syntax, a format
specifier that is incompatible with the given arguments,
insufficient arguments given the format string, or other
illegal conditions. For specification of all possible
formatting errors, see the Details section of the
formatter class specification.
NullPointerException
- If the format is nullFormatter
public static String format(Locale l, String format, Object... args)
l
- The locale to apply during
formatting. If l is null then no localization
is applied.format
- A format stringargs
- Arguments referenced by the format specifiers in the format
string. If there are more arguments than format specifiers, the
extra arguments are ignored. The number of arguments is
variable and may be zero. The maximum number of arguments is
limited by the maximum dimension of a Java array as defined by
the Java
Virtual Machine Specification. The behaviour on a
null argument depends on the conversion.
IllegalFormatException
- If a format string contains an illegal syntax, a format
specifier that is incompatible with the given arguments,
insufficient arguments given the format string, or other
illegal conditions. For specification of all possible
formatting errors, see the Details section of the
formatter class specification
NullPointerException
- If the format is nullFormatter
public boolean isEmpty()
length()
is 0.
length()
is 0, otherwise
false
|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |