Save This Page
Home » apache-harmony-6.0-src-r917296-snapshot » java » lang » [javadoc | source]
java.lang
public final class: String [javadoc | source]
java.lang.Object
   java.lang.String

All Implemented Interfaces:
    CharSequence, Comparable, Serializable

An immutable sequence of characters/code units ({@code char}s). A {@code 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 ({@code char}).
Nested Class Summary:
static class  String.ConsolePrintStream  An PrintStream used for System.out which performs the correct character conversion for the console, since the console may use a different conversion than the default file.encoding. 
Field Summary
public static final  Comparator<String> CASE_INSENSITIVE_ORDER    A comparator ignoring the case of the characters. 
Constructor:
 public String() 
 public String(byte[] data) 
 public String(char[] data) 
 public String(String string) 
    Creates a {@code String} that is a copy of the specified string.
    Parameters:
    string - the string to copy.
 public String(StringBuffer stringbuffer) 
    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) 
    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) 
 public String(byte[] data,
    String encoding) throws UnsupportedEncodingException 
    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) 
    Converts the byte array to a String using the specified encoding.
 public String(byte[] data,
    int start,
    int length) 
 public String(char[] data,
    int start,
    int length) 
 String(int start,
    int length,
    char[] data) 
 public String(int[] codePoints,
    int offset,
    int count) 
 public String(byte[] data,
    int high,
    int start,
    int length) 
 public String(byte[] data,
    int start,
    int length,
    String encoding) throws UnsupportedEncodingException 
    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) 
    Converts the byte array to a String using the specified encoding.
Method from java.lang.String Summary:
charAt,   codePointAt,   codePointBefore,   codePointCount,   compareTo,   compareToIgnoreCase,   concat,   contains,   contentEquals,   contentEquals,   copyValueOf,   copyValueOf,   endsWith,   equals,   equalsIgnoreCase,   format,   format,   getBytes,   getBytes,   getBytes,   getBytes,   getChars,   getValue,   hashCode,   indexOf,   indexOf,   indexOf,   indexOf,   intern,   isEmpty,   lastIndexOf,   lastIndexOf,   lastIndexOf,   lastIndexOf,   length,   matches,   offsetByCodePoints,   regionMatches,   regionMatches,   replace,   replace,   replaceAll,   replaceFirst,   split,   split,   startsWith,   startsWith,   subSequence,   substring,   substring,   toCharArray,   toLowerCase,   toLowerCase,   toString,   toUpperCase,   toUpperCase,   trim,   valueOf,   valueOf,   valueOf,   valueOf,   valueOf,   valueOf,   valueOf,   valueOf,   valueOf
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.lang.String Detail:
 public char charAt(int index) 
    Returns the character at the specified offset in this string.
 public int codePointAt(int index) 
    Retrieves the Unicode code point (character) value at the specified {@code index}.
 public int codePointBefore(int index) 
    Retrieves the Unicode code point value that precedes the specified {@code index}.
 public int codePointCount(int beginIndex,
    int endIndex) 
    Calculates the number of Unicode code points between {@code beginIndex} and {@code endIndex}.
 public int compareTo(String string) 
    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) 
    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) 
    Concatenates this string and the specified string.
 public boolean contains(CharSequence cs) 
    Determines if this {@code String} contains the sequence of characters in the {@code CharSequence} passed.
 public boolean contentEquals(StringBuffer strbuf) 
    Returns whether the characters in the StringBuffer {@code strbuf} are the same as those in this string.
 public boolean contentEquals(CharSequence cs) 
    Compares a {@code CharSequence} to this {@code String} to determine if their contents are equal.
 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.
 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.
 public boolean endsWith(String suffix) 
    Compares the specified string to this string to determine if the specified string is a suffix.
 public boolean equals(Object object) 
    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) 
    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) 
    Returns a formatted string, using the supplied format and arguments, using the default locale.
 public static String format(Locale loc,
    String format,
    Object args) 
    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() 
    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 
    Converts this string to a byte array using the specified encoding.
 public byte[] getBytes(Charset encoding) 
    Converts this String to a byte encoding using the specified encoding.
 public  void getBytes(int start,
    int end,
    byte[] data,
    int index) 
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) 
    Copies the specified characters in this string to the character array starting at the specified offset in the character array.
 char[] getValue() 
 public int hashCode() 
 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.
 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.
 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.
 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.
 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. 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() 
    Answers if the size of this String is zero.
 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.
 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.
 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.
 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.
 public int length() 
    Returns the size of this string.
 public boolean matches(String expr) 
    Determines whether this string matches a given regular expression.
 public int offsetByCodePoints(int index,
    int codePointOffset) 
    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) 
    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) 
    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) 
    Copies this string replacing occurrences of the specified character with another character.
 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.
 public String replaceAll(String expr,
    String 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) 
    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) 
    Splits this string using the supplied regular expression {@code expr}.
 public String[] split(String expr,
    int 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) 
    Compares the specified string to this string to determine if the specified string is a prefix.
 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.
 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.
 public String substring(int start) 
    Copies a range of characters into a new string.
 public String substring(int start,
    int end) 
    Copies a range of characters into a new string.
 public char[] toCharArray() 
    Copies the characters in this string to a character array.
 public String toLowerCase() 
    Converts the characters in this string to lowercase, using the default Locale.
 public String toLowerCase(Locale locale) 
    Converts the characters in this string to lowercase, using the specified Locale.
 public String toString() 
    Returns this string.
 public String toUpperCase() 
    Converts the characters in this string to uppercase, using the default Locale.
 public String toUpperCase(Locale locale) 
    Converts the characters in this string to uppercase, using the specified Locale.
 public String trim() 
    Copies this string removing white space characters from the beginning and end of the string.
 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.
 public static String valueOf(char value) 
    Converts the specified character to its string representation.
 public static String valueOf(double value) 
    Converts the specified double to its string representation.
 public static String valueOf(float value) 
    Converts the specified float to its string representation.
 public static String valueOf(int value) 
    Converts the specified integer to its string representation.
 public static String valueOf(long value) 
    Converts the specified long to its string representation.
 public static String valueOf(Object value) 
    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) 
    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) 
    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.