| Constructor: |
public String() {
value = new char[0];
offset = 0;
count = 0;
}
|
public String(byte[] data) {
this(data, 0, data.length);
}
Converts the byte array to a string using the default encoding as
specified by the file.encoding system property. If the system property is
not defined, the default encoding is ISO8859_1 (ISO-Latin-1). If 8859-1
is not available, an ASCII encoding is used. Parameters:
data -
the byte array to convert to a string.
|
public String(char[] data) {
this(data, 0, data.length);
}
Initializes this string to contain the characters in the specified
character array. Modifying the character array after creating the string
has no effect on the string. Parameters:
data -
the array of characters.
Throws:
NullPointerException -
when {@code data} is {@code null}.
|
public String(String string) {
value = string.value;
offset = string.offset;
count = string.count;
}
Creates a {@code String} that is a copy of the specified string. Parameters:
string -
the string to copy.
|
public String(StringBuffer stringbuffer) {
offset = 0;
synchronized (stringbuffer) {
value = stringbuffer.shareValue();
count = stringbuffer.length();
}
}
Creates a {@code String} from the contents of the specified
{@code StringBuffer}. Parameters:
stringbuffer -
the buffer to get the contents from.
|
public String(StringBuilder sb) {
if (sb == null) {
throw new NullPointerException();
}
this.offset = 0;
this.count = sb.length();
this.value = new char[this.count];
sb.getChars(0, this.count, this.value, 0);
}
Creates a {@code String} from the contents of the specified {@code
StringBuilder}. Parameters:
sb -
the {@code StringBuilder} to copy the contents from.
Throws:
NullPointerException -
if {@code sb} is {@code null}.
- since:
1.5 -
|
public String(byte[] data,
int high) {
this(data, high, 0, data.length);
}
Converts the byte array to a string, setting the high byte of every
character to the specified value. Parameters:
data -
the byte array to convert to a string.
high -
the high byte to use.
Throws:
NullPointerException -
when {@code data} is {@code null}.
|
public String(byte[] data,
String encoding) throws UnsupportedEncodingException {
this(data, 0, data.length, encoding);
}
Converts the byte array to a string using the specified encoding. Parameters:
data -
the byte array to convert to a string.
encoding -
the encoding.
Throws:
NullPointerException -
when {@code data} is {@code null}.
UnsupportedEncodingException -
if {@code encoding} is not supported.
|
public String(byte[] data,
Charset encoding) {
this(data, 0, data.length, encoding);
}
Converts the byte array to a String using the specified encoding. |
public String(byte[] data,
int start,
int length) {
// start + length could overflow, start/length maybe MaxInt
if (start >= 0 && 0 < = length && length < = data.length - start) {
offset = 0;
Charset charset = defaultCharset();
int result;
CharBuffer cb = charset
.decode(ByteBuffer.wrap(data, start, length));
if ((result = cb.length()) > 0) {
value = cb.array();
count = result;
} else {
count = 0;
value = new char[0];
}
} else {
throw new StringIndexOutOfBoundsException();
}
}
Converts the byte array to a string using the default encoding as
specified by the file.encoding system property. If the system property is
not defined, the default encoding is ISO8859_1 (ISO-Latin-1). If 8859-1
is not available, an ASCII encoding is used. Parameters:
data -
the byte array to convert to a string.
start -
the starting offset in the byte array.
length -
the number of bytes to convert.
Throws:
NullPointerException -
when {@code data} is {@code null}.
IndexOutOfBoundsException -
if {@code length < 0, start < 0} or {@code start + length >
data.length}.
|
public String(char[] data,
int start,
int length) {
// range check everything so a new char[] is not created
// start + length could overflow, start/length maybe MaxInt
if (start >= 0 && 0 < = length && length < = data.length - start) {
offset = 0;
value = new char[length];
count = length;
System.arraycopy(data, start, value, 0, count);
} else {
throw new StringIndexOutOfBoundsException();
}
}
Initializes this string to contain the specified characters in the
character array. Modifying the character array after creating the string
has no effect on the string. Parameters:
data -
the array of characters.
start -
the starting offset in the character array.
length -
the number of characters to use.
Throws:
NullPointerException -
when {@code data} is {@code null}.
IndexOutOfBoundsException -
if {@code length < 0, start < 0} or {@code start + length >
data.length}
|
String(int start,
int length,
char[] data) {
value = data;
offset = start;
count = length;
}
|
public String(int[] codePoints,
int offset,
int count) {
super();
if (codePoints == null) {
throw new NullPointerException();
}
if (offset < 0 || count < 0
|| (long) offset + (long) count > codePoints.length) {
throw new IndexOutOfBoundsException();
}
this.offset = 0;
this.value = new char[count * 2];
int end = offset + count;
int c = 0;
for (int i = offset; i < end; i++) {
c += Character.toChars(codePoints[i], this.value, c);
}
this.count = c;
}
Creates a {@code String} from the sub-array of Unicode code points. Parameters:
codePoints -
the array of Unicode code points to convert.
offset -
the inclusive index into {@code codePoints} to begin
converting from.
count -
the number of elements in {@code codePoints} to copy.
Throws:
NullPointerException -
if {@code codePoints} is {@code null}.
IllegalArgumentException -
if any of the elements of {@code codePoints} are not valid
Unicode code points.
IndexOutOfBoundsException -
if {@code offset} or {@code count} are not within the bounds
of {@code codePoints}.
- since:
1.5 -
|
public String(byte[] data,
int high,
int start,
int length) {
if (data != null) {
// start + length could overflow, start/length maybe MaxInt
if (start >= 0 && 0 < = length && length < = data.length - start) {
offset = 0;
value = new char[length];
count = length;
high < < = 8;
for (int i = 0; i < count; i++) {
value[i] = (char) (high + (data[start++] & 0xff));
}
} else {
throw new StringIndexOutOfBoundsException();
}
} else {
throw new NullPointerException();
}
}
Converts the byte array to a string, setting the high byte of every
character to the specified value. Parameters:
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.
Throws:
NullPointerException -
when {@code data} is {@code null}.
IndexOutOfBoundsException -
if {@code length < 0, start < 0} or
{@code start + length > data.length}
|
public String(byte[] data,
int start,
int length,
String encoding) throws UnsupportedEncodingException {
if (encoding == null) {
throw new NullPointerException();
}
// start + length could overflow, start/length maybe MaxInt
if (start >= 0 && 0 < = length && length < = data.length - start) {
offset = 0;
Charset charset = getCharset(encoding);
int result;
CharBuffer cb;
try {
cb = charset.decode(ByteBuffer.wrap(data, start, length));
} catch (Exception e) {
// do nothing. according to spec:
// behavior is unspecified for invalid array
cb = CharBuffer.wrap("\u003f".toCharArray()); //$NON-NLS-1$
}
if ((result = cb.length()) > 0) {
value = cb.array();
count = result;
} else {
count = 0;
value = new char[0];
}
} else {
throw new StringIndexOutOfBoundsException();
}
}
Converts the byte array to a string using the specified encoding. Parameters:
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.
Throws:
NullPointerException -
when {@code data} is {@code null}.
IndexOutOfBoundsException -
if {@code length < 0, start < 0} or {@code start + length >
data.length}.
UnsupportedEncodingException -
if {@code encoding} is not supported.
|
public String(byte[] data,
int start,
int length,
Charset encoding) {
if (encoding == null) {
throw new NullPointerException();
}
// start + length could overflow, start/length maybe MaxInt
if (start >= 0 && 0 < = length && length < = data.length - start) {
offset = 0;
lastCharset = encoding;
CharBuffer cb = encoding
.decode(ByteBuffer.wrap(data, start, length));
value = cb.array();
count = cb.length();
} else {
throw new StringIndexOutOfBoundsException();
}
}
Converts the byte array to a String using the specified encoding. |
| Method from java.lang.String Detail: |
public char charAt(int index) {
if (0 < = index && index < count) {
return value[offset + index];
}
throw new StringIndexOutOfBoundsException();
}
Returns the character at the specified offset in this string. |
public int codePointAt(int index) {
if (index < 0 || index >= count) {
throw new IndexOutOfBoundsException();
}
int s = index + offset;
return Character.codePointAt(value, s, offset + count);
}
Retrieves the Unicode code point (character) value at the specified
{@code index}. |
public int codePointBefore(int index) {
if (index < 1 || index > count) {
throw new IndexOutOfBoundsException();
}
int s = index + offset;
return Character.codePointBefore(value, s);
}
Retrieves the Unicode code point value that precedes the specified
{@code index}. |
public int codePointCount(int beginIndex,
int endIndex) {
if (beginIndex < 0 || endIndex > count || beginIndex > endIndex) {
throw new IndexOutOfBoundsException();
}
int s = beginIndex + offset;
return Character.codePointCount(value, s, endIndex - beginIndex);
}
Calculates the number of Unicode code points between {@code beginIndex}
and {@code endIndex}. |
public int compareTo(String string) {
// Code adapted from K&R, pg 101
int o1 = offset, o2 = string.offset, result;
int end = offset + (count < string.count ? count : string.count);
char[] target = string.value;
while (o1 < end) {
if ((result = value[o1++] - target[o2++]) != 0) {
return result;
}
}
return count - string.count;
}
Compares the specified string to this string using the Unicode values of
the characters. Returns 0 if the strings contain the same characters in
the same order. Returns a negative integer if the first non-equal
character in this string has a Unicode value which is less than the
Unicode value of the character at the same position in the specified
string, or if this string is a prefix of the specified string. Returns a
positive integer if the first non-equal character in this string has a
Unicode value which is greater than the Unicode value of the character at
the same position in the specified string, or if the specified string is
a prefix of this string. |
public int compareToIgnoreCase(String string) {
int o1 = offset, o2 = string.offset, result;
int end = offset + (count < string.count ? count : string.count);
char c1, c2;
char[] target = string.value;
while (o1 < end) {
if ((c1 = value[o1++]) == (c2 = target[o2++])) {
continue;
}
c1 = compareValue(c1);
c2 = compareValue(c2);
if ((result = c1 - c2) != 0) {
return result;
}
}
return count - string.count;
}
Compares the specified string to this string using the Unicode values of
the characters, ignoring case differences. Returns 0 if the strings
contain the same characters in the same order. Returns a negative integer
if the first non-equal character in this string has a Unicode value which
is less than the Unicode value of the character at the same position in
the specified string, or if this string is a prefix of the specified
string. Returns a positive integer if the first non-equal character in
this string has a Unicode value which is greater than the Unicode value
of the character at the same position in the specified string, or if the
specified string is a prefix of this string. |
public String concat(String string) {
if (string.count > 0 && count > 0) {
char[] buffer = new char[count + string.count];
System.arraycopy(value, offset, buffer, 0, count);
System.arraycopy(string.value, string.offset, buffer, count,
string.count);
return new String(0, buffer.length, buffer);
}
return count == 0 ? string : this;
}
Concatenates this string and the specified string. |
public boolean contains(CharSequence cs) {
if (cs == null) {
throw new NullPointerException();
}
return indexOf(cs.toString()) >= 0;
}
Determines if this {@code String} contains the sequence of characters in
the {@code CharSequence} passed. |
public boolean contentEquals(StringBuffer strbuf) {
synchronized (strbuf) {
int size = strbuf.length();
if (count != size) {
return false;
}
return regionMatches(0, new String(0, size, strbuf.getValue()), 0,
size);
}
}
Returns whether the characters in the StringBuffer {@code strbuf} are the
same as those in this string. |
public boolean contentEquals(CharSequence cs) {
if (cs == null) {
throw new NullPointerException();
}
int len = cs.length();
if (len != count) {
return false;
}
if (len == 0 && count == 0) {
return true; // since both are empty strings
}
return regionMatches(0, cs.toString(), 0, len);
}
Compares a {@code CharSequence} to this {@code String} to determine if
their contents are equal. |
public static String copyValueOf(char[] data) {
return new String(data, 0, data.length);
}
Creates a new string containing the characters in the specified character
array. Modifying the character array after creating the string has no
effect on the string. |
public static String copyValueOf(char[] data,
int start,
int length) {
return new String(data, start, length);
}
Creates a new string containing the specified characters in the character
array. Modifying the character array after creating the string has no
effect on the string. |
public boolean endsWith(String suffix) {
return regionMatches(count - suffix.count, suffix, 0, suffix.count);
}
Compares the specified string to this string to determine if the
specified string is a suffix. |
public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object instanceof String) {
String s = (String) object;
int hash = hashCode; // Single read on hashCodes as they may change
int shash = s.hashCode;
if (count != s.count || (hash != shash && hash != 0 && shash != 0)) {
return false;
}
for (int i = 0; i < count; ++i) {
if (value[offset + i] != s.value[s.offset + i]) {
return false;
}
}
return true;
}
return false;
}
Compares the specified object to this string and returns true if they are
equal. The object must be an instance of string with the same characters
in the same order. |
public boolean equalsIgnoreCase(String string) {
if (string == this) {
return true;
}
if (string == null || count != string.count) {
return false;
}
int o1 = offset, o2 = string.offset;
int end = offset + count;
char c1, c2;
char[] target = string.value;
while (o1 < end) {
if ((c1 = value[o1++]) != (c2 = target[o2++])
&& toUpperCase(c1) != toUpperCase(c2)
// Required for unicode that we test both cases
&& toLowerCase(c1) != toLowerCase(c2)) {
return false;
}
}
return true;
}
Compares the specified string to this string ignoring the case of the
characters and returns true if they are equal. |
public static String format(String format,
Object args) {
return format(Locale.getDefault(), format, args);
}
Returns a formatted string, using the supplied format and arguments,
using the default locale. |
public static String format(Locale loc,
String format,
Object args) {
if (format == null) {
throw new NullPointerException("null format argument");
}
int bufferSize = format.length()
+ (args == null ? 0 : args.length * 10);
Formatter f = new Formatter(new StringBuilder(bufferSize), loc);
return f.format(format, args).toString();
}
Returns a formatted string, using the supplied format and arguments,
accordingly to the specified locale.
Note that this is a convenience method. Using it involves creating an
internal java.util.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
java.util.Formatter instance instead. |
public byte[] getBytes() {
ByteBuffer buffer = defaultCharset().encode(
CharBuffer.wrap(this.value, this.offset, this.count));
byte[] bytes = new byte[buffer.limit()];
buffer.get(bytes);
return bytes;
}
Converts this string to a byte array using the default encoding as
specified by the file.encoding system property. If the system property is
not defined, the default encoding is ISO8859_1 (ISO-Latin-1). If 8859-1
is not available, an ASCII encoding is used. |
public byte[] getBytes(String encoding) throws UnsupportedEncodingException {
ByteBuffer buffer = getCharset(encoding).encode(
CharBuffer.wrap(this.value, this.offset, this.count));
byte[] bytes = new byte[buffer.limit()];
buffer.get(bytes);
return bytes;
}
Converts this string to a byte array using the specified encoding. |
public byte[] getBytes(Charset encoding) {
ByteBuffer buffer = encoding.encode(CharBuffer.wrap(this.value,
this.offset, this.count));
byte[] bytes = new byte[buffer.limit()];
buffer.get(bytes);
return bytes;
}
Converts this String to a byte encoding using the specified encoding. |
public void getBytes(int start,
int end,
byte[] data,
int index) {
if (0 < = start && start < = end && end < = count) {
end += offset;
try {
for (int i = offset + start; i < end; i++) {
data[index++] = (byte) value[i];
}
} catch (ArrayIndexOutOfBoundsException e) {
throw new StringIndexOutOfBoundsException();
}
} else {
throw new StringIndexOutOfBoundsException();
}
} Deprecated! Use - #getBytes() or #getBytes(String)
Converts this string to a byte array, ignoring the high order bits of
each character. |
public void getChars(int start,
int end,
char[] buffer,
int index) {
// NOTE last character not copied!
// Fast range check.
if (0 < = start && start < = end && end < = count) {
System.arraycopy(value, start + offset, buffer, index, end - start);
} else {
throw new StringIndexOutOfBoundsException();
}
}
Copies the specified characters in this string to the character array
starting at the specified offset in the character array. |
char[] getValue() {
return value;
}
|
public int hashCode() {
if (hashCode == 0) {
if (count == 0) {
return 0;
}
int hash = 0;
for (int i = offset; i < count + offset; i++) {
hash = value[i] + ((hash < < 5) - hash);
}
hashCode = hash;
}
return hashCode;
}
|
public int indexOf(int c) {
return indexOf(c, 0);
}
Searches in this string for the first index of the specified character.
The search for the character starts at the beginning and moves towards
the end of this string. |
public int indexOf(String string) {
return indexOf(string, 0);
}
Searches in this string for the first index of the specified string. The
search for the string starts at the beginning and moves towards the end
of this string. |
public int indexOf(int c,
int start) {
if (start < count) {
if (start < 0) {
start = 0;
}
for (int i = offset + start; i < offset + count; i++) {
if (value[i] == c) {
return i - offset;
}
}
}
return -1;
}
Searches in this string for the index of the specified character. The
search for the character starts at the specified offset and moves towards
the end of this string. |
public int indexOf(String subString,
int start) {
if (start < 0) {
start = 0;
}
int subCount = subString.count;
if (subCount > 0) {
if (subCount + start > count) {
return -1;
}
char[] target = subString.value;
int subOffset = subString.offset;
char firstChar = target[subOffset];
int end = subOffset + subCount;
while (true) {
int i = indexOf(firstChar, start);
if (i == -1 || subCount + i > count) {
return -1; // handles subCount > count || start >= count
}
int o1 = offset + i, o2 = subOffset;
while (++o2 < end && value[++o1] == target[o2]) {
// Intentionally empty
}
if (o2 == end) {
return i;
}
start = i + 1;
}
}
return start < count ? start : count;
}
Searches in this string for the index of the specified string. The search
for the string starts at the specified offset and moves towards the end
of this string. |
public String intern() {
return VM.intern(this);
}
Searches an internal table of strings for a string equal to this string.
If the string is not in the table, it is added. Returns the string
contained in the table which is equal to this string. The same string
object is always returned for strings which are equal. |
public boolean isEmpty() {
return 0 == count;
}
Answers if the size of this String is zero. |
public int lastIndexOf(int c) {
return lastIndexOf(c, count - 1);
}
Searches in this string for the last index of the specified character.
The search for the character starts at the end and moves towards the
beginning of this string. |
public int lastIndexOf(String string) {
// Use count instead of count - 1 so lastIndexOf("") answers count
return lastIndexOf(string, count);
}
Searches in this string for the last index of the specified string. The
search for the string starts at the end and moves towards the beginning
of this string. |
public int lastIndexOf(int c,
int start) {
if (start >= 0) {
if (start >= count) {
start = count - 1;
}
for (int i = offset + start; i >= offset; --i) {
if (value[i] == c) {
return i - offset;
}
}
}
return -1;
}
Searches in this string for the index of the specified character. The
search for the character starts at the specified offset and moves towards
the beginning of this string. |
public int lastIndexOf(String subString,
int start) {
int subCount = subString.count;
if (subCount < = count && start >= 0) {
if (subCount > 0) {
if (start > count - subCount) {
start = count - subCount;
}
// count and subCount are both >= 1
char[] target = subString.value;
int subOffset = subString.offset;
char firstChar = target[subOffset];
int end = subOffset + subCount;
while (true) {
int i = lastIndexOf(firstChar, start);
if (i == -1) {
return -1;
}
int o1 = offset + i, o2 = subOffset;
while (++o2 < end && value[++o1] == target[o2]) {
// Intentionally empty
}
if (o2 == end) {
return i;
}
start = i - 1;
}
}
return start < count ? start : count;
}
return -1;
}
Searches in this string for the index of the specified string. The search
for the string starts at the specified offset and moves towards the
beginning of this string. |
public int length() {
return count;
}
Returns the size of this string. |
public boolean matches(String expr) {
return Pattern.matches(expr, this);
}
Determines whether this string matches a given regular expression. |
public int offsetByCodePoints(int index,
int codePointOffset) {
int s = index + offset;
int r = Character.offsetByCodePoints(value, offset, count, s,
codePointOffset);
return r - offset;
}
Returns the index within this object that is offset from {@code index} by
{@code codePointOffset} code points. |
public boolean regionMatches(int thisStart,
String string,
int start,
int length) {
if (string == null) {
throw new NullPointerException();
}
if (start < 0 || string.count - start < length) {
return false;
}
if (thisStart < 0 || count - thisStart < length) {
return false;
}
if (length < = 0) {
return true;
}
int o1 = offset + thisStart, o2 = string.offset + start;
for (int i = 0; i < length; ++i) {
if (value[o1 + i] != string.value[o2 + i]) {
return false;
}
}
return true;
}
Compares the specified string to this string and compares the specified
range of characters to determine if they are the same. |
public boolean regionMatches(boolean ignoreCase,
int thisStart,
String string,
int start,
int length) {
if (!ignoreCase) {
return regionMatches(thisStart, string, start, length);
}
if (string != null) {
if (thisStart < 0 || length > count - thisStart) {
return false;
}
if (start < 0 || length > string.count - start) {
return false;
}
thisStart += offset;
start += string.offset;
int end = thisStart + length;
char c1, c2;
char[] target = string.value;
while (thisStart < end) {
if ((c1 = value[thisStart++]) != (c2 = target[start++])
&& toUpperCase(c1) != toUpperCase(c2)
// Required for unicode that we test both cases
&& toLowerCase(c1) != toLowerCase(c2)) {
return false;
}
}
return true;
}
throw new NullPointerException();
}
Compares the specified string to this string and compares the specified
range of characters to determine if they are the same. When ignoreCase is
true, the case of the characters is ignored during the comparison. |
public String replace(char oldChar,
char newChar) {
int index = indexOf(oldChar, 0);
if (index == -1) {
return this;
}
char[] buffer = new char[count];
System.arraycopy(value, offset, buffer, 0, count);
do {
buffer[index++] = newChar;
} while ((index = indexOf(oldChar, index)) != -1);
return new String(0, count, buffer);
}
Copies this string replacing occurrences of the specified character with
another character. |
public String replace(CharSequence target,
CharSequence replacement) {
if (target == null) {
throw new NullPointerException("target should not be null");
}
if (replacement == null) {
throw new NullPointerException("replacement should not be null");
}
String ts = target.toString();
int index = indexOf(ts, 0);
if (index == -1)
return this;
String rs = replacement.toString();
StringBuilder buffer = new StringBuilder(count);
int tl = target.length();
int tail = 0;
do {
buffer.append(value, offset + tail, index - tail);
buffer.append(rs);
tail = index + tl;
} while ((index = indexOf(ts, tail)) != -1);
//append trailing chars
buffer.append(value, offset + tail, count - tail);
return buffer.toString();
}
Copies this string replacing occurrences of the specified target sequence
with another sequence. The string is processed from the beginning to the
end. |
public String replaceAll(String expr,
String substitute) {
return Pattern.compile(expr).matcher(this).replaceAll(substitute);
}
Replace any substrings within this string that match the supplied regular
expression {@code expr}, with the string {@code substitute}. |
public String replaceFirst(String expr,
String substitute) {
return Pattern.compile(expr).matcher(this).replaceFirst(substitute);
}
Replace the first substring within this string that matches the supplied
regular expression {@code expr}, with the string {@code substitute}. |
public String[] split(String expr) {
return Pattern.compile(expr).split(this);
}
Splits this string using the supplied regular expression {@code expr}. |
public String[] split(String expr,
int max) {
return Pattern.compile(expr).split(this, max);
}
Splits this string using the supplied regular expression {@code expr}.
The parameter {@code max} controls the behavior how many times the
pattern is applied to the string. |
public boolean startsWith(String prefix) {
return startsWith(prefix, 0);
}
Compares the specified string to this string to determine if the
specified string is a prefix. |
public boolean startsWith(String prefix,
int start) {
return regionMatches(start, prefix, 0, prefix.count);
}
Compares the specified string to this string, starting at the specified
offset, to determine if the specified string is a prefix. |
public CharSequence subSequence(int start,
int end) {
return substring(start, end);
}
Has the same result as the substring function, but is present so that
string may implement the CharSequence interface. |
public String substring(int start) {
if (start == 0) {
return this;
}
if (0 < = start && start < = count) {
return new String(offset + start, count - start, value);
}
throw new StringIndexOutOfBoundsException(start);
}
Copies a range of characters into a new string. |
public String substring(int start,
int end) {
if (start == 0 && end == count) {
return this;
}
// NOTE last character not copied!
// Fast range check.
if (0 < = start && start < = end && end < = count) {
return new String(offset + start, end - start, value);
}
throw new StringIndexOutOfBoundsException();
}
Copies a range of characters into a new string. |
public char[] toCharArray() {
char[] buffer = new char[count];
System.arraycopy(value, offset, buffer, 0, count);
return buffer;
}
Copies the characters in this string to a character array. |
public String toLowerCase() {
return toLowerCase(Locale.getDefault());
}
Converts the characters in this string to lowercase, using the default
Locale. |
public String toLowerCase(Locale locale) {
for (int o = offset, end = offset + count; o < end; o++) {
char ch = value[o];
if (ch != toLowerCase(ch)) {
char[] buffer = new char[count];
int i = o - offset;
// Not worth checking for i == 0 case
System.arraycopy(value, offset, buffer, 0, i);
// Turkish
if (!"tr".equals(locale.getLanguage())) { //$NON-NLS-1$
while (i < count) {
buffer[i++] = toLowerCase(value[o++]);
}
} else {
while (i < count) {
buffer[i++] = (ch = value[o++]) != 0x49 ? toLowerCase(ch)
: (char) 0x131;
}
}
return new String(0, count, buffer);
}
}
return this;
}
Converts the characters in this string to lowercase, using the specified
Locale. |
public String toString() {
return this;
}
|
public String toUpperCase() {
return toUpperCase(Locale.getDefault());
}
Converts the characters in this string to uppercase, using the default
Locale. |
public String toUpperCase(Locale locale) {
boolean turkish = "tr".equals(locale.getLanguage()); //$NON-NLS-1$
char[] output = null;
int i = 0;
for (int o = offset, end = offset + count; o < end; o++) {
char ch = value[o];
int index = upperIndex(ch);
if (index == -1) {
if (output != null && i >= output.length) {
char[] newoutput = new char[output.length + (count / 6) + 2];
System.arraycopy(output, 0, newoutput, 0, output.length);
output = newoutput;
}
char upch = !turkish ? toUpperCase(ch)
: (ch != 0x69 ? toUpperCase(ch)
: (char) 0x130);
if (ch != upch) {
if (output == null) {
output = new char[count];
i = o - offset;
System.arraycopy(value, offset, output, 0, i);
}
output[i++] = upch;
} else if (output != null) {
output[i++] = ch;
}
} else {
int target = index * 3;
char val3 = upperValues[target + 2];
if (output == null) {
output = new char[count + (count / 6) + 2];
i = o - offset;
System.arraycopy(value, offset, output, 0, i);
} else if (i + (val3 == 0 ? 1 : 2) >= output.length) {
char[] newoutput = new char[output.length + (count / 6) + 3];
System.arraycopy(output, 0, newoutput, 0, output.length);
output = newoutput;
}
char val = upperValues[target];
output[i++] = val;
val = upperValues[target + 1];
output[i++] = val;
if (val3 != 0) {
output[i++] = val3;
}
}
}
if (output == null) {
return this;
}
return output.length == i || output.length - i < 8 ? new String(0, i,
output) : new String(output, 0, i);
}
Converts the characters in this string to uppercase, using the specified
Locale. |
public String trim() {
int start = offset, last = offset + count - 1;
int end = last;
while ((start < = end) && (value[start] < = ' ')) {
start++;
}
while ((end >= start) && (value[end] < = ' ')) {
end--;
}
if (start == offset && end == last) {
return this;
}
return new String(start, end - start + 1, value);
}
Copies this string removing white space characters from the beginning and
end of the string. |
public static String valueOf(char[] data) {
return new String(data, 0, data.length);
}
Creates a new string containing the characters in the specified character
array. Modifying the character array after creating the string has no
effect on the string. |
public static String valueOf(char value) {
String s;
if (value < 128) {
s = new String(value, 1, ascii);
} else {
s = new String(0, 1, new char[] { value });
}
s.hashCode = value;
return s;
}
Converts the specified character to its string representation. |
public static String valueOf(double value) {
return Double.toString(value);
}
Converts the specified double to its string representation. |
public static String valueOf(float value) {
return Float.toString(value);
}
Converts the specified float to its string representation. |
public static String valueOf(int value) {
return Integer.toString(value);
}
Converts the specified integer to its string representation. |
public static String valueOf(long value) {
return Long.toString(value);
}
Converts the specified long to its string representation. |
public static String valueOf(Object value) {
return value != null ? value.toString() : "null"; //$NON-NLS-1$
}
Converts the specified object to its string representation. If the object
is null return the string {@code "null"}, otherwise use {@code
toString()} to get the string representation. |
public static String valueOf(boolean value) {
return value ? "true" : "false"; //$NON-NLS-1$ //$NON-NLS-2$
}
Converts the specified boolean to its string representation. When the
boolean is {@code true} return {@code "true"}, otherwise return {@code
"false"}. |
public static String valueOf(char[] data,
int start,
int length) {
return new String(data, start, length);
}
Creates a new string containing the specified characters in the character
array. Modifying the character array after creating the string has no
effect on the string. |