Reference:Java.lang.String
From Triled Wiki
java.lang
public final class java.lang.String
| java.lang.Object | ||
| java.lang.String | Serializable CharSequence Comparable | |
An immutable sequence of characters/code units (chars). A String is represented by array of UTF-16 values, such that Unicode supplementary characters (code points) are stored/encoded as surrogate pairs via Unicode code units (char)
See Also
[edit] Summary
[edit] Constants
| Value | ||||
|---|---|---|---|---|
| Comparator | CASE_INSENSITIVE_ORDER |
[edit] Public Constructors
| String () | |||||
| Answers an empty string. | |||||
| String (byte[] data) | |||||
| Converts the byte array to a String using the default encoding as specified by the file.encoding system property. | |||||
| String (byte[] data, int high) | |||||
| This constructor is deprecated. Use String(byte[]) or String(byte[], String) instead | |||||
| String (byte[] data, int start, int length) | |||||
| Converts the byte array to a String using the default encoding as specified by the file.encoding system property. | |||||
| String (byte[] data, int high, int start, int length) | |||||
| This constructor is deprecated. Use String(byte[], int, int) instead | |||||
| String (byte[] data, int start, int length, String encoding) | |||||
| Converts the byte array to a String using the specified encoding. | |||||
| String (byte[] data, String encoding) | |||||
| Converts the byte array to a String using the specified encoding. | |||||
| String (char[] data) | |||||
| Initializes this String to contain the characters in the specified character array. | |||||
| String (char[] data, int start, int length) | |||||
| Initializes this String to contain the specified characters in the character array. | |||||
| String (String string) | |||||
| Creates a string that is a copy of another string | |||||
| String (StringBuffer stringbuffer) | |||||
| Creates a string from the contents of a StringBuffer. | |||||
| String (int[] codePoints, int offset, int count) | |||||
|
Constructs a String from the sub-array of Unicode code points. | |||||
| String (StringBuilder sb) | |||||
|
Constructs a String from a StringBuilder. | |||||
[edit] Public Methods
| char | charAt (int index) | ||||
| Answers the character at the specified offset in this String. | |||||
| int | codePointAt (int index) | ||||
|
Retrieves the Unicode code point value at the index. | |||||
| int | codePointBefore (int index) | ||||
|
Retrieves the Unicode code point value that precedes the index. | |||||
| int | codePointCount (int beginIndex, int endIndex) | ||||
|
Calculates the number of Unicode code points between beginIndex and endIndex. | |||||
| int | compareTo (String string) | ||||
| Compares the specified String to this String using the Unicode values of the characters. | |||||
| int | compareToIgnoreCase (String string) | ||||
| Compare the receiver to the specified String to determine the relative ordering when the case of the characters is ignored. | |||||
| String | concat (String string) | ||||
| Concatenates this String and the specified string. | |||||
| boolean | contains (CharSequence cs) | ||||
|
Determines if this String contains the sequence of characters in the CharSequence passed. | |||||
| boolean | contentEquals (StringBuffer strbuf) | ||||
| Answers whether the characters in the StringBuffer strbuf are the same as those in this String. | |||||
| boolean | contentEquals (CharSequence cs) | ||||
|
Compares a CharSequence to this String to determine if their contents are equal. | |||||
| static | String | copyValueOf (char[] data) | |||
| Creates a new String containing the characters in the specified character array. | |||||
| static | String | copyValueOf (char[] data, int start, int length) | |||
| Creates a new String containing the specified characters in the character array. | |||||
| boolean | endsWith (String suffix) | ||||
| Compares the specified string to this String to determine if the specified string is a suffix. | |||||
| boolean | equals (Object object) | ||||
| Compares the specified object to this String and answer if they are equal. | |||||
| boolean | equalsIgnoreCase (String string) | ||||
| Compares the specified String to this String ignoring the case of the characters and answer if they are equal. | |||||
| static | String | format (String format, Object[ ] args) | |||
| Returns a printf-style formatted string, using the supplied format and arguments. | |||||
| static | String | format (Locale loc, String format, Object[ ] args) | |||
| Returns a printf-style formatted string, using the supplied format and arguments, accordingly to the specified locale. | |||||
| void | getBytes (int start, int end, byte[] data, int index) | ||||
| This method is deprecated. Use getBytes() or getBytes(String) | |||||
| byte[] | getBytes () | ||||
| Converts this String to a byte encoding using the default encoding as specified by the file.encoding system property. | |||||
| byte[] | getBytes (String encoding) | ||||
| Converts this String to a byte encoding using the specified encoding. | |||||
| void | getChars (int start, int end, char[] buffer, int index) | ||||
| Copies the specified characters in this String to the character array starting at the specified offset in the character array. | |||||
| int | hashCode () | ||||
| Answers an integer hash code for the receiver. | |||||
| int | indexOf (int c, int start) | ||||
| Searches in this String for the index of the specified character. | |||||
| int | indexOf (int c) | ||||
| Searches in this String for the first index of the specified character. | |||||
| int | indexOf (String subString, int start) | ||||
| Searches in this String for the index of the specified string. | |||||
| int | indexOf (String string) | ||||
| Searches in this String for the first index of the specified string. | |||||
| String | intern () | ||||
| Searches an internal table of strings for a string equal to this String. | |||||
| int | lastIndexOf (int c) | ||||
| Searches in this String for the last index of the specified character. | |||||
| int | lastIndexOf (String string) | ||||
| Searches in this String for the last index of the specified string. | |||||
| int | lastIndexOf (String subString, int start) | ||||
| Searches in this String for the index of the specified string. | |||||
| int | lastIndexOf (int c, int start) | ||||
| Searches in this String for the index of the specified character. | |||||
| int | length () | ||||
| Answers the size of this String. | |||||
| boolean | matches (String expr) | ||||
| Determines whether a this String matches a given regular expression. | |||||
| int | offsetByCodePoints (int index, int codePointOffset) | ||||
|
Returns the index within this object that is offset from index by codePointOffset code points. | |||||
| boolean | regionMatches (int thisStart, String string, int start, int length) | ||||
| Compares the specified string to this String and compares the specified range of characters to determine if they are the same. | |||||
| boolean | regionMatches (boolean ignoreCase, int thisStart, String string, int start, int length) | ||||
| Compares the specified string to this String and compares the specified range of characters to determine if they are the same. | |||||
| String | replace (char oldChar, char newChar) | ||||
| Copies this String replacing occurrences of the specified character with another character. | |||||
| String | replace (CharSequence target, CharSequence replacement) | ||||
| Copies this String replacing occurrences of the specified target sequence with another sequence. | |||||
| String | replaceAll (String expr, String substitute) | ||||
| Replace any substrings within this String that match the supplied regular expression expr, with the String substitute. | |||||
| String | replaceFirst (String expr, String substitute) | ||||
| Replace the first substring within this String that matches the supplied regular expression expr, with the String substitute. | |||||
| String[ ] | split (String expr, int max) | ||||
| Splits this String using the supplied regular expression expr. | |||||
| String[ ] | split (String expr) | ||||
| Splits this String using the supplied regular expression expr. | |||||
| boolean | startsWith (String prefix, int start) | ||||
| Compares the specified string to this String, starting at the specified offset, to determine if the specified string is a prefix. | |||||
| boolean | startsWith (String prefix) | ||||
| Compares the specified string to this String to determine if the specified string is a prefix. | |||||
| CharSequence | subSequence (int start, int end) | ||||
| Has the same result as the substring function, but is present so that String may implement the CharSequence interface. | |||||
| String | substring (int start, int end) | ||||
| Copies a range of characters into a new String. | |||||
| String | substring (int start) | ||||
| Copies a range of characters into a new String. | |||||
| char[] | toCharArray () | ||||
| Copies the characters in this String to a character array. | |||||
| String | toLowerCase (Locale locale) | ||||
| Converts the characters in this String to lowercase, using the specified Locale. | |||||
| String | toLowerCase () | ||||
| Converts the characters in this String to lowercase, using the default Locale. | |||||
| String | toString () | ||||
| Answers a string containing a concise, human-readable description of the receiver. | |||||
| String | toUpperCase (Locale locale) | ||||
| Converts the characters in this String to uppercase, using the specified Locale. | |||||
| String | toUpperCase () | ||||
| Converts the characters in this String to uppercase, using the default Locale. | |||||
| String | trim () | ||||
| Copies this String removing white space characters from the beginning and end of the string. | |||||
| static | String | valueOf (float value) | |||
| Converts the specified float to its string representation. | |||||
| static | String | valueOf (boolean value) | |||
| Converts the specified boolean to its string representation. | |||||
| static | String | valueOf (double value) | |||
| Converts the specified double to its string representation. | |||||
| static | String | valueOf (char value) | |||
| Converts the specified character to its string representation. | |||||
| static | String | valueOf (char[] data) | |||
| Creates a new String containing the characters in the specified character array. | |||||
| static | String | valueOf (char[] data, int start, int length) | |||
| Creates a new String containing the specified characters in the character array. | |||||
| static | String | valueOf (long value) | |||
| Converts the specified long to its string representation. | |||||
| static | String | valueOf (int value) | |||
| Converts the specified integer to its string representation. | |||||
| static | String | valueOf (Object value) | |||
| Converts the specified object to its string representation. | |||||
[edit] Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait[edit] Methods inherited from interface java.lang.CharSequence
charAt, length, subSequence, toString[edit] Methods inherited from interface java.lang.Comparable
[edit] Details
[edit] Constants
[edit] public static final Comparator CASE_INSENSITIVE_ORDER
[edit] Public Constructors
[edit] public String()
Answers an empty string.
[edit] public String(byte[] data)
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 |
|---|
Throws
| NullPointerException | when data is null |
|---|
See Also
- getBytes()
- getBytes(int, int, byte[], int)
- getBytes(String)
- valueOf(boolean)
- valueOf(char)
- valueOf(char[])
- valueOf(char[], int, int)
- valueOf(double)
- valueOf(float)
- valueOf(int)
- valueOf(long)
- valueOf(Object)
[edit] public String(byte[] data, int high)
This constructor is deprecated. Use String(byte[]) or String(byte[], String) insteadConverts 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 data is null |
|---|
[edit] public String(byte[] data, int start, int length)
Converts the byte array to a String using the default encoding as specified by the file.encoding system property. 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
| IndexOutOfBoundsException | when length < 0, start < 0 or start + length > data.length |
|---|---|
| NullPointerException | when data is null |
See Also
- getBytes()
- getBytes(int, int, byte[], int)
- getBytes(String)
- valueOf(boolean)
- valueOf(char)
- valueOf(char[])
- valueOf(char[], int, int)
- valueOf(double)
- valueOf(float)
- valueOf(int)
- valueOf(long)
- valueOf(Object)
[edit] public String(byte[] data, int high, int start, int length)
This constructor is deprecated. Use String(byte[], int, int) insteadConverts 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
| IndexOutOfBoundsException | when length < 0, start < 0 or start + length > data.length |
|---|---|
| NullPointerException | when data is null |
[edit] public String(byte[] data, int start, int length, String encoding)
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
| IndexOutOfBoundsException | when length < 0, start < 0 or start + length > data.length |
|---|---|
| UnsupportedEncodingException | when encoding is not supported |
| NullPointerException | when data is null |
See Also
- getBytes()
- getBytes(int, int, byte[], int)
- getBytes(String)
- valueOf(boolean)
- valueOf(char)
- valueOf(char[])
- valueOf(char[], int, int)
- valueOf(double)
- valueOf(float)
- valueOf(int)
- valueOf(long)
- valueOf(Object)
- UnsupportedEncodingException
[edit] public String(byte[] data, String 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
| UnsupportedEncodingException | when encoding is not supported |
|---|---|
| NullPointerException | when data is null |
See Also
- getBytes()
- getBytes(int, int, byte[], int)
- getBytes(String)
- valueOf(boolean)
- valueOf(char)
- valueOf(char[])
- valueOf(char[], int, int)
- valueOf(double)
- valueOf(float)
- valueOf(int)
- valueOf(long)
- valueOf(Object)
- UnsupportedEncodingException
[edit] public String(char[] data)
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 data is null |
|---|
[edit] public String(char[] data, int start, int length)
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
| IndexOutOfBoundsException | when length < 0, start < 0 or start + length > data.length |
|---|---|
| NullPointerException | when data is null |
[edit] public String(String string)
Creates a string that is a copy of another string
Parameters
| string | the String to copy |
|---|
[edit] public String(StringBuffer stringbuffer)
Creates a string from the contents of a StringBuffer.
Parameters
| stringbuffer | the StringBuffer |
|---|
[edit] public String(int[] codePoints, int offset, int count)
Constructs a String from the sub-array of Unicode code points.
Parameters
| codePoints | The array of Unicode code points to convert. |
|---|---|
| offset | The inclusive index into codePoints to begin converting from. |
| count | The number of element in codePoints to copy. |
Throws
| NullPointerException | if codePoints is null. |
|---|---|
| IllegalArgumentException | if any of the elements of codePoints are not valid Unicode code points. |
| IndexOutOfBoundsException | if offset or count are not within the bounds of codePoints. |
[edit] public String(StringBuilder sb)
Constructs a String from a StringBuilder.
Parameters
| sb | The StringBuilder to copy from. |
|---|
Throws
| NullPointerException | if sb is null. |
|---|
[edit] Public Methods
[edit] public char charAt(int index)
Answers the character at the specified offset in this String.
Parameters
| index | the zero-based index in this string |
|---|
Returns
- the character at the index
Throws
| IndexOutOfBoundsException | when index < 0 or index >= length() |
|---|
[edit] public int codePointAt(int index)
Retrieves the Unicode code point value at the index.
Parameters
| index | The index to the char code unit within this object. |
|---|
Returns
- The Unicode code point value.
Throws
| IndexOutOfBoundsException | if index is negative or greater than or equal to length(). |
|---|
See Also
[edit] public int codePointBefore(int index)
Retrieves the Unicode code point value that precedes the index.
Parameters
| index | The index to the char code unit within this object. |
|---|
Returns
- The Unicode code point value.
Throws
| IndexOutOfBoundsException | if index is less than 1 or greater than length(). |
|---|
See Also
[edit] public int codePointCount(int beginIndex, int endIndex)
Calculates the number of Unicode code points between beginIndex and endIndex.
Parameters
| beginIndex | The inclusive beginning index of the subsequence. |
|---|---|
| endIndex | The exclusive end index of the subsequence. |
Returns
- The number of Unicode code points in the subsequence.
Throws
| IndexOutOfBoundsException | if beginIndex is negative or greater than endIndex or endIndex is greater than length(). |
|---|
[edit] public int compareTo(String string)
Compares the specified String to this String using the Unicode values of the characters. Answer 0 if the strings contain the same characters in the same order. Answer 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. Answer 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 the this String.
Parameters
| string | the string to compare |
|---|
Returns
- 0 if the strings are equal, a negative integer if this String is before the specified String, or a positive integer if this String is after the specified String
Throws
| NullPointerException | when string is null |
|---|
[edit] public int compareToIgnoreCase(String string)
Compare the receiver to the specified String to determine the relative ordering when the case of the characters is ignored.
Parameters
| string | a String |
|---|
Returns
- an int < 0 if this String is less than the specified String, 0 if they are equal, and > 0 if this String is greater
[edit] public String concat(String string)
Concatenates this String and the specified string.
Parameters
| string | the string to concatenate |
|---|
Returns
- a new String which is the concatenation of this String and the specified String
Throws
| NullPointerException | if string is null |
|---|
[edit] public boolean contains(CharSequence cs)
Determines if this String contains the sequence of characters in the CharSequence passed.
Parameters
| cs | The character sequence to search for. |
|---|
Returns
- true if the sequence of characters are contained in this object; otherwise false
[edit] public boolean contentEquals(StringBuffer strbuf)
Answers whether the characters in the StringBuffer strbuf are the same as those in this String.
Parameters
| strbuf | the StringBuffer to compare this String to |
|---|
Returns
- true when the characters in strbuf are identical to those in this String. If they are not, false will be returned.
Throws
| NullPointerException | when strbuf is null |
|---|
[edit] public boolean contentEquals(CharSequence cs)
Compares a CharSequence to this String to determine if their contents are equal.
Parameters
| cs | The character sequence to compare to. |
|---|
Returns
- true if equal, otherwise false
[edit] public static String copyValueOf(char[] data)
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.
Parameters
| data | the array of characters |
|---|
Returns
- the new String
Throws
| NullPointerException | if data is null |
|---|
[edit] public static String copyValueOf(char[] data, int start, int 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.
Parameters
| data | the array of characters |
|---|---|
| start | the starting offset in the character array |
| length | the number of characters to use |
Returns
- the new String
Throws
| IndexOutOfBoundsException | if length < 0, start < 0 or start + length > data.length |
|---|---|
| NullPointerException | if data is null |
[edit] public boolean endsWith(String suffix)
Compares the specified string to this String to determine if the specified string is a suffix.
Parameters
| suffix | the string to look for |
|---|
Returns
- true when the specified string is a suffix of this String, false otherwise
Throws
| NullPointerException | if suffix is null |
|---|
[edit] public boolean equals(Object object)
Compares the specified object to this String and answer if they are equal. The object must be an instance of String with the same characters in the same order.
Parameters
| object | the object to compare |
|---|
Returns
- true if the specified object is equal to this String, false otherwise
See Also
[edit] public boolean equalsIgnoreCase(String string)
Compares the specified String to this String ignoring the case of the characters and answer if they are equal.
Parameters
| string | the string to compare |
|---|
Returns
- true if the specified string is equal to this String, false otherwise
[edit] public static String format(String format, Object[ ] args)
Returns a printf-style formatted string, using the supplied format and arguments. This function is a shortcut to format(Locale.getDefault(), format, args).
Parameters
| format | a format string |
|---|---|
| args | arguments to replace format specifiers, may be none |
Returns
- The formatted string
Throws
| NullPointerException | if the format is null |
|---|---|
| IllegalArgumentException | if the format is invalid |
See Also
[edit] public static String format(Locale loc, String format, Object[ ] args)
Returns a printf-style formatted string, using the supplied format and arguments, accordingly to the specified locale.
Parameters
| loc | the locale to apply; null value means no localization |
|---|---|
| format | a format string |
| args | arguments to replace format specifiers, may be none |
Returns
- The formatted string
Throws
| NullPointerException | if the format is null |
|---|---|
| IllegalArgumentException | if the format is invalid |
See Also
[edit] public void getBytes(int start, int end, byte[] data, int index)
This method is deprecated. Use getBytes() or getBytes(String)Converts this String to a byte array, ignoring the high order bits of each character.
Parameters
| start | the starting offset of characters to copy |
|---|---|
| end | the ending offset of characters to copy |
| data | the destination byte array |
| index | the starting offset in the byte array |
Throws
| NullPointerException | when data is null |
|---|---|
| IndexOutOfBoundsException | when start < 0, end > length(), index < 0, end - start > data.length - index |
[edit] public byte[] getBytes()
Converts this String to a byte encoding 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.
Returns
- the byte array encoding of this String
See Also
- String
[edit] public byte[] getBytes(String encoding)
Converts this String to a byte encoding using the specified encoding.
Parameters
| encoding | the encoding |
|---|
Returns
- the byte array encoding of this String
Throws
| UnsupportedEncodingException | when the encoding is not supported |
|---|
See Also
- String
- UnsupportedEncodingException
[edit] public void getChars(int start, int end, char[] buffer, int index)
Copies the specified characters in this String to the character array starting at the specified offset in the character array.
Parameters
| start | the starting offset of characters to copy |
|---|---|
| end | the ending offset of characters to copy |
| buffer | the destination character array |
| index | the starting offset in the character array |
Throws
| IndexOutOfBoundsException | when start < 0, end > length(), start > end, index < 0, end - start > buffer.length - index |
|---|---|
| NullPointerException | when buffer is null |
[edit] public int hashCode()
Answers an integer hash code for the receiver. Objects which are equal answer the same value for this method.
Returns
- the receiver's hash
See Also
[edit] public int indexOf(int c, int start)
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.
Parameters
| c | the character to find |
|---|---|
| start | the starting offset |
Returns
- the index in this String of the specified character, -1 if the character isn't found
See Also
[edit] public int indexOf(int c)
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.
Parameters
| c | the character to find |
|---|
Returns
- the index in this String of the specified character, -1 if the character isn't found
See Also
[edit] public int indexOf(String subString, int start)
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.
Parameters
| subString | the string to find |
|---|---|
| start | the starting offset |
Returns
- the index in this String of the specified string, -1 if the string isn't found
Throws
| NullPointerException | when string is null |
|---|
See Also
[edit] public int indexOf(String string)
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.
Parameters
| string | the string to find |
|---|
Returns
- the index in this String of the specified string, -1 if the string isn't found
Throws
| NullPointerException | when string is null |
|---|
See Also
[edit] public String intern()
Searches an internal table of strings for a string equal to this String. If the string is not in the table, it is added. Answers the string contained in the table which is equal to this String. The same string object is always answered for strings which are equal.
Returns
- the interned string equal to this String
[edit] public int lastIndexOf(int c)
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.
Parameters
| c | the character to find |
|---|
Returns
- the index in this String of the specified character, -1 if the character isn't found
See Also
[edit] public int lastIndexOf(String string)
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.
Parameters
| string | the string to find |
|---|
Returns
- the index in this String of the specified string, -1 if the string isn't found
Throws
| NullPointerException | when string is null |
|---|
See Also
[edit] public int lastIndexOf(String subString, int start)
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.
Parameters
| subString | the string to find |
|---|---|
| start | the starting offset |
Returns
- the index in this String of the specified string, -1 if the string isn't found
Throws
| NullPointerException | when string is null |
|---|
See Also
[edit] public int lastIndexOf(int c, int start)
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.
Parameters
| c | the character to find |
|---|---|
| start | the starting offset |
Returns
- the index in this String of the specified character, -1 if the character isn't found
See Also
[edit] public int length()
Answers the size of this String.
Returns
- the number of characters in this String
[edit] public boolean matches(String expr)
Determines whether a this String matches a given regular expression.
Parameters
| expr | the regular expression to be matched |
|---|
Returns
- true if the expression matches, otherwise false
Throws
| PatternSyntaxException | if the syntax of the supplied regular expression is not valid |
|---|---|
| NullPointerException | if expr is null |
[edit] public int offsetByCodePoints(int index, int codePointOffset)
Returns the index within this object that is offset from index by codePointOffset code points.
Parameters
| index | The index within this object to calculate the offset from. |
|---|---|
| codePointOffset | The number of code points to count. |
Returns
- The index within this object that is the offset.
Throws
| IndexOutOfBoundsException | if index is negative or greater than length() or if there aren't enough code points before or after index to match codePointOffset. |
|---|
[edit] public boolean regionMatches(int thisStart, String string, int start, int length)
Compares the specified string to this String and compares the specified range of characters to determine if they are the same.
Parameters
| thisStart | the starting offset in this String |
|---|---|
| string | the string to compare |
| start | the starting offset in string |
| length | the number of characters to compare |
Returns
- true if the ranges of characters is equal, false otherwise
Throws
| NullPointerException | when string is null |
|---|
[edit] public boolean regionMatches(boolean ignoreCase, int thisStart, String string, int start, int length)
Compares the specified string to this String and compares the specified range of characters to determine if they are the same. When ignoreCase is true, the case of the characters is ignored during the comparison.
Parameters
| ignoreCase | specifies if case should be ignored |
|---|---|
| thisStart | the starting offset in this String |
| string | the string to compare |
| start | the starting offset in string |
| length | the number of characters to compare |
Returns
- true if the ranges of characters is equal, false otherwise
Throws
| NullPointerException | when string is null |
|---|
[edit] public String replace(char oldChar, char newChar)
Copies this String replacing occurrences of the specified character with another character.
Parameters
| oldChar | the character to replace |
|---|---|
| newChar | the replacement character |
Returns
- a new String with occurrences of oldChar replaced by newChar
[edit] public String replace(CharSequence target, CharSequence replacement)
Copies this String replacing occurrences of the specified target sequence with another sequence. The string is processed from the beginning to the end.
Parameters
| target | the sequence to replace |
|---|---|
| replacement | the replacement sequence |
Returns
- the resulting String
Throws
| NullPointerException | if either of the arguments is null |
|---|
[edit] public String replaceAll(String expr, String substitute)
Replace any substrings within this String that match the supplied regular expression expr, with the String substitute.
Parameters
| expr | the regular expression to match |
|---|---|
| substitute | the string to replace the matching substring with |
Returns
- the new string
Throws
| NullPointerException | if expr is null |
|---|
[edit] public String replaceFirst(String expr, String substitute)
Replace the first substring within this String that matches the supplied regular expression expr, with the String substitute.
Parameters
| expr | the regular expression to match |
|---|---|
| substitute | the string to replace the matching substring with |
Returns
- the new string
Throws
| NullPointerException | if expr is null |
|---|
[edit] public String[ ]split(String expr, int max)
Splits this String using the supplied regular expression expr. max controls the number of times that the pattern is applied to the string.
Parameters
| expr | the regular expression used to divide the string |
|---|---|
| max | the number of times to apply the pattern |
Returns
- an array of Strings created by separating the string along matches of the regular expression.
Throws
| NullPointerException | if expr is null |
|---|
[edit] public String[ ]split(String expr)
Splits this String using the supplied regular expression expr.
Parameters
| expr | the regular expression used to divide the string |
|---|
Returns
- an array of Strings created by separating the string along matches of the regular expression.
Throws
| NullPointerException | if expr is null |
|---|
[edit] public boolean startsWith(String prefix, int start)
Compares the specified string to this String, starting at the specified offset, to determine if the specified string is a prefix.
Parameters
| prefix | the string to look for |
|---|---|
| start | the starting offset |
Returns
- true when the specified string occurs in this String at the specified offset, false otherwise
Throws
| NullPointerException | when prefix is null |
|---|
[edit] public boolean startsWith(String prefix)
Compares the specified string to this String to determine if the specified string is a prefix.
Parameters
| prefix | the string to look for |
|---|
Returns
- true when the specified string is a prefix of this String, false otherwise
Throws
| NullPointerException | when prefix is null |
|---|
[edit] public CharSequence subSequence(int start, int end)
Has the same result as the substring function, but is present so that String may implement the CharSequence interface.
Parameters
| start | the offset the first character |
|---|---|
| end | the offset of one past the last character to include |
Returns
- the subsequence requested
Throws
| IndexOutOfBoundsException | when start or end is less than zero, start is greater than end, or end is greater than the length of the String. |
|---|
See Also
[edit] public String substring(int start, int end)
Copies a range of characters into a new String.
Parameters
| start | the offset of the first character |
|---|---|
| end | the offset one past the last character |
Returns
- a new String containing the characters from start to end - 1
Throws
| IndexOutOfBoundsException | when start < 0, start > end or end > length() |
|---|
[edit] public String substring(int start)
Copies a range of characters into a new String.
Parameters
| start | the offset of the first character |
|---|
Returns
- a new String containing the characters from start to the end of the string
Throws
| IndexOutOfBoundsException | when start < 0 or start > length() |
|---|
[edit] public char[] toCharArray()
Copies the characters in this String to a character array.
Returns
- a character array containing the characters of this String
[edit] public String toLowerCase(Locale locale)
Converts the characters in this String to lowercase, using the specified Locale.
Parameters
| locale | the Locale |
|---|
Returns
- a new String containing the lowercase characters equivalent to the characters in this String
[edit] public String toLowerCase()
Converts the characters in this String to lowercase, using the default Locale.
Returns
- a new String containing the lowercase characters equivalent to the characters in this String
[edit] public String toString()
Answers a string containing a concise, human-readable description of the receiver.
Returns
- this String
[edit] public String toUpperCase(Locale locale)
Converts the characters in this String to uppercase, using the specified Locale.
Parameters
| locale | the Locale |
|---|
Returns
- a new String containing the uppercase characters equivalent to the characters in this String
[edit] public String toUpperCase()
Converts the characters in this String to uppercase, using the default Locale.
Returns
- a new String containing the uppercase characters equivalent to the characters in this String
[edit] public String trim()
Copies this String removing white space characters from the beginning and end of the string.
Returns
- a new String with characters <= \\u0020 removed from the beginning and the end
[edit] public static String valueOf(float value)
Converts the specified float to its string representation.
Parameters
| value | the float |
|---|
Returns
- the float converted to a string
[edit] public static String valueOf(boolean value)
Converts the specified boolean to its string representation. When the boolean is true answer "true", otherwise answer "false".
Parameters
| value | the boolean |
|---|
Returns
- the boolean converted to a string
[edit] public static String valueOf(double value)
Converts the specified double to its string representation.
Parameters
| value | the double |
|---|
Returns
- the double converted to a string
[edit] public static String valueOf(char value)
Converts the specified character to its string representation.
Parameters
| value | the character |
|---|
Returns
- the character converted to a string
[edit] public static String valueOf(char[] data)
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.
Parameters
| data | the array of characters |
|---|
Returns
- the new String
Throws
| NullPointerException | when data is null |
|---|
[edit] public static String valueOf(char[] data, int start, int 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.
Parameters
| data | the array of characters |
|---|---|
| start | the starting offset in the character array |
| length | the number of characters to use |
Returns
- the new String
Throws
| IndexOutOfBoundsException | when length < 0, start < 0 or start + length > data.length |
|---|---|
| NullPointerException | when data is null |
[edit] public static String valueOf(long value)
Converts the specified long to its string representation.
Parameters
| value | the long |
|---|
Returns
- the long converted to a string
[edit] public static String valueOf(int value)
Converts the specified integer to its string representation.
Parameters
| value | the integer |
|---|
Returns
- the integer converted to a string