+ All Categories
Home > Documents > Java.lang.String English

Java.lang.String English

Date post: 05-Apr-2018
Category:
Upload: song-don-gian
View: 226 times
Download: 0 times
Share this document with a friend

of 39

Transcript
  • 7/31/2019 Java.lang.String English

    1/39

    ]

    Class String

    java.lang.Object

    java.lang.String

    All Implemented Interfaces:CharSequence,Comparable,Serializable

    public final classStringextendsObjectimplementsSerializable,Comparable,CharSequence

    TheStringclass represents character strings. All string literals in Java programs, suchas"abc", are implemented as instances of this class.

    Strings are constant; their values cannot be changed after they are created. Stringbuffers support mutable strings. Because String objects are immutable they can beshared. For example:

    String str = "abc";

    is equivalent to:

    char data[] = {'a', 'b', 'c'};

    String str = new String(data);

    Here are some more examples of how strings can be used:

    System.out.println("abc");

    String cde = "cde";

    System.out.println("abc" + cde);

    String c = "abc".substring(2,3);

    String d = cde.substring(1, 2);

    The classStringincludes methods for examining individual characters of thesequence, for comparing strings, for searching strings, for extracting substrings, andfor creating a copy of a string with all characters translated to uppercase or tolowercase. Case mapping relies heavily on the information provided by the UnicodeConsortium's Unicode 3.0 specification. The specification's UnicodeData.txt andSpecialCasing.txt files are used extensively to provide case mapping.

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Comparable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Comparable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Comparable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/Serializable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/Serializable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/Serializable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/Serializable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/Serializable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/Serializable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Comparable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Comparable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Comparable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Comparable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/Serializable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/Serializable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Comparable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html
  • 7/31/2019 Java.lang.String English

    2/39

  • 7/31/2019 Java.lang.String English

    3/39

    String(byte[] ascii, int hibyte, int offset, int count)Deprecated.This method does not properly convert bytes into characters. As

    of JDK 1.1, the preferred way to do this is via theStringconstructors that take a

    charset name or that use the platform's default charset.

    String(byte[] bytes, int offset, int length, String charsetName)Constructs a newStringby decoding the specified subarray of bytes using thespecified charset.

    String(byte[] bytes, StringcharsetName)Constructs a newStringby decoding the specified array of bytes using the

    specified charset.

    String(char[] value)Allocates a newStringso that it represents the sequence of characters

    currently contained in the character array argument.

    String(char[] value, int offset, int count)Allocates a newStringthat contains characters from a subarray of the

    character array argument.

    String(Stringoriginal)Initializes a newly createdStringobject so that it represents the same sequence

    of characters as the argument; in other words, the newly created string is a copy ofthe argument string.

    String(StringBuffer buffer)Allocates a new string that contains the sequence of characters currently

    contained in the string buffer argument.

    Method Summarychar charAt(int index)

    Returns the character at the specified index.int compareTo(Object o)

    Compares this String to another Object.int compareTo(StringanotherString)

    Compares two strings lexicographically.int compareToIgnoreCase(String str)

    Compares two strings lexicographically, ignoring casedifferences.

    String concat(String str)Concatenates the specified string to the end of this string.

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#String(byte[],%20int,%20int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#String(byte[],%20int,%20int,%20java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#String(byte[],%20java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#String(char[])http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#String(char[],%20int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#String(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#String(java.lang.StringBuffer)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/StringBuffer.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#charAt(int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#charAt(int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#compareTo(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#compareTo(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#compareToIgnoreCase(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#concat(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#concat(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#compareToIgnoreCase(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#compareTo(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#compareTo(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#charAt(int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/StringBuffer.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#String(java.lang.StringBuffer)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#String(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#String(char[],%20int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#String(char[])http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#String(byte[],%20java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#String(byte[],%20int,%20int,%20java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#String(byte[],%20int,%20int,%20int)
  • 7/31/2019 Java.lang.String English

    4/39

    boolean contentEquals(StringBuffersb)Returnstrueif and only if thisStringrepresents the same

    sequence of characters as the specifiedStringBuffer.

    static String copyValueOf(char[] data)

    Returns a String that represents the character sequence in thearray specified.

    static String copyValueOf(char[] data, int offset, int count)Returns a String that represents the character sequence in the

    array specified.boolean endsWith(String suffix)

    Tests if this string ends with the specified suffix.boolean equals(Object anObject)

    Compares this string to the specified object.

    boolean equalsIgnoreCase(String anotherString)Compares thisStringto anotherString, ignoring case

    considerations.byte[] getBytes()

    Encodes thisStringinto a sequence of bytes using the platform'sdefault charset, storing the result into a new byte array.

    void getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin)Deprecated.This method does not properly convert characters

    into bytes. As of JDK 1.1, the preferred way to do this is via the

    thegetBytes()method, which uses the platform's default charset.byte[] getBytes(String charsetName)

    Encodes thisStringinto a sequence of bytes using the namedcharset, storing the result into a new byte array.

    void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)Copies characters from this string into the destination character

    array.int hashCode()

    Returns a hash code for this string.

    int indexOf(int ch)Returns the index within this string of the first occurrence of the

    specified character.int indexOf(int ch, int fromIndex)

    Returns the index within this string of the first occurrence of thespecified character, starting the search at the specified index.

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#contentEquals(java.lang.StringBuffer)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/StringBuffer.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/StringBuffer.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#copyValueOf(char[])http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#copyValueOf(char[],%20int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#endsWith(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equalsIgnoreCase(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#getBytes()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#getBytes(int,%20int,%20byte[],%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#getBytes(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#getChars(int,%20int,%20char[],%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#hashCode()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#indexOf(int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#indexOf(int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#indexOf(int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#indexOf(int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#hashCode()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#getChars(int,%20int,%20char[],%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#getBytes(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#getBytes(int,%20int,%20byte[],%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#getBytes()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equalsIgnoreCase(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#endsWith(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#copyValueOf(char[],%20int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#copyValueOf(char[])http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/StringBuffer.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#contentEquals(java.lang.StringBuffer)
  • 7/31/2019 Java.lang.String English

    5/39

    int indexOf(String str)Returns the index within this string of the first occurrence of the

    specified substring.Tr v mt ch s c gi tr l intVd: nguyen van hung.index(h) = 11; y k t h ng vtr 12;

    int indexOf(String str, int fromIndex)Returns the index within this string of the first occurrence of the

    specified substring, starting at the specified index.

    String intern()Returns a canonical representation for the string object.

    int lastIndexOf(int ch)Returns the index within this string of the last occurrence of the

    specified character.Tr v mt ch s c gi tr l int

    int lastIndexOf(int ch, int fromIndex)Returns the index within this string of the last occurrence of the

    specified character, searching backward starting at the specified index.int lastIndexOf(String str)

    Returns the index within this string of the rightmost occurrenceof the specified substring.

    intlastIndexOf(String str, int fromIndex)Returns the index within this string of the last occurrence of thespecified substring, searching backward starting at the specified index.

    int length()Returns the length of this string.

    boolean matches(String regex)Tells whether or not this string matches the givenregular

    expression.boolean regionMatches(boolean ignoreCase, int toffset,String other,

    int ooffset, int len)

    Tests if two string regions are equal.boolean regionMatches(int toffset, String other, int ooffset, int len)

    Tests if two string regions are equal.

    String replace(char oldChar, char newChar)Returns a new string resulting from replacing all occurrences

    ofoldCharin this string withnewChar.

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#indexOf(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#indexOf(java.lang.String,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#intern()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#lastIndexOf(int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#lastIndexOf(int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#lastIndexOf(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#lastIndexOf(java.lang.String,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#length()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#matches(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#matches(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#regionMatches(boolean,%20int,%20java.lang.String,%20int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#regionMatches(boolean,%20int,%20java.lang.String,%20int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#regionMatches(int,%20java.lang.String,%20int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#regionMatches(int,%20java.lang.String,%20int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#replace(char,%20char)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#replace(char,%20char)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#regionMatches(int,%20java.lang.String,%20int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#regionMatches(boolean,%20int,%20java.lang.String,%20int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#matches(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#length()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#lastIndexOf(java.lang.String,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#lastIndexOf(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#lastIndexOf(int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#lastIndexOf(int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#intern()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#indexOf(java.lang.String,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#indexOf(java.lang.String)
  • 7/31/2019 Java.lang.String English

    6/39

    String replaceAll(Stringregex, String replacement)Replaces each substring of this string that matches the

    givenregular expressionwith the given replacement.

    String replaceFirst(String regex, String replacement)

    Replaces the first substring of this string that matches thegivenregular expressionwith the given replacement.

    String[] split(String regex)Splits this string around matches of the givenregular expression.

    String[] split(String regex, int limit)Splits this string around matches of the givenregular expression.

    boolean startsWith(Stringprefix)Tests if this string starts with the specified prefix.

    boolean startsWith(Stringprefix, int toffset)

    Tests if this string starts with the specified prefix beginning aspecified index.

    CharSequence subSequence(int beginIndex, int endIndex)Returns a new character sequence that is a subsequence of this

    sequence.

    String substring(int beginIndex)Returns a new string that is a substring of this string.

    String substring(int beginIndex, int endIndex)Returns a new string that is a substring of this string.

    char[] toCharArray()Converts this string to a new character array.

    String toLowerCase()Converts all of the characters in thisStringto lower case using

    the rules of the default locale.

    String toLowerCase(Locale locale)Converts all of the characters in thisStringto lower case using

    the rules of the givenLocale.

    String toString()

    This object (which is already a string!) is itself returned.

    String toUpperCase()Converts all of the characters in thisStringto upper case using

    the rules of the default locale.

    String toUpperCase(Localelocale)Converts all of the characters in thisStringto upper case using

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#replaceAll(java.lang.String,%20java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#replaceFirst(java.lang.String,%20java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#replaceFirst(java.lang.String,%20java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#split(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#split(java.lang.String,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#startsWith(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#startsWith(java.lang.String,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#subSequence(int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#substring(int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#substring(int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#toCharArray()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#toCharArray()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#toLowerCase()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#toLowerCase()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#toLowerCase(java.util.Locale)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#toLowerCase(java.util.Locale)http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Locale.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#toString()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#toUpperCase()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#toUpperCase(java.util.Locale)http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Locale.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/Locale.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/Locale.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#toUpperCase(java.util.Locale)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#toUpperCase()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#toString()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/Locale.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#toLowerCase(java.util.Locale)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#toLowerCase()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#toCharArray()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#substring(int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#substring(int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#subSequence(int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#startsWith(java.lang.String,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#startsWith(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#split(java.lang.String,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#split(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#replaceFirst(java.lang.String,%20java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#replaceAll(java.lang.String,%20java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html
  • 7/31/2019 Java.lang.String English

    7/39

    the rules of the givenLocale.

    String trim()Returns a copy of the string, with leading and trailing whitespace

    omitted.

    static String valueOf(boolean b)Returns the string representation of thebooleanargument.

    static String valueOf(char c)Returns the string representation of thecharargument.

    static String valueOf(char[] data)Returns the string representation of thechararray argument.

    static String valueOf(char[] data, int offset, int count)Returns the string representation of a specific subarray of

    thechararray argument.

    static String valueOf(double d)Returns the string representation of thedoubleargument.

    static String valueOf(float f)Returns the string representation of thefloatargument.

    static String valueOf(int i)Returns the string representation of theintargument.

    static String valueOf(long l)Returns the string representation of thelongargument.

    static String valueOf(Object obj)Returns the string representation of theObjectargument.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify,notifyAll,wait, wait, wait

    Field Detail

    CASE_INSENSITIVE_ORDER

    public static finalComparatorCASE_INSENSITIVE_ORDER

    A Comparator that ordersStringobjects as bycompareToIgnoreCase. Thiscomparator is serializable.

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#trim()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#valueOf(boolean)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#valueOf(char)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#valueOf(char[])http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#valueOf(char[],%20int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#valueOf(double)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#valueOf(float)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#valueOf(int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#valueOf(long)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#valueOf(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#clone()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#finalize()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#getClass()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#notify()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#notify()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#notifyAll()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#notifyAll()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#wait()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#wait(long)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#wait(long,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#wait(long,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Comparator.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/Comparator.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/Comparator.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#wait(long,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#wait(long)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#wait()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#notifyAll()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#notify()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#getClass()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#finalize()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#clone()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#valueOf(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#valueOf(long)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#valueOf(int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#valueOf(float)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#valueOf(double)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#valueOf(char[],%20int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#valueOf(char[])http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#valueOf(char)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#valueOf(boolean)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#trim()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html
  • 7/31/2019 Java.lang.String English

    8/39

    Note that this Comparator doesnottake locale into account, and will result inan unsatisfactory ordering for certain locales. The java.text packageprovidesCollatorsto allow locale-sensitive ordering.

    Since:

    1.2See Also:Collator.compare(String, String)

    Constructor Detail

    String

    public String()

    Initializes a newly createdStringobject so that it represents an empty charactersequence. Note that use of this constructor is unnecessary since Strings areimmutable.

    String

    public String(String original)

    Initializes a newly createdStringobject so that it represents the same sequenceof characters as the argument; in other words, the newly created string is a copyof the argument string. Unless an explicit copy oforiginalis needed, use of thisconstructor is unnecessary since Strings are immutable.

    Parameters:original- aString.

    String

    public String(char[] value)

    Allocates a newStringso that it represents the sequence of characters currentlycontained in the character array argument. The contents of the character arrayare copied; subsequent modification of the character array does not affect the

    newly created string.Parameters:value- the initial value of the string.

    String

    public String(char[] value,

    http://docs.oracle.com/javase/1.4.2/docs/api/java/text/Collator.html#compare(java.lang.String,%20java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/text/Collator.html#compare(java.lang.String,%20java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/text/Collator.html#compare(java.lang.String,%20java.lang.String)
  • 7/31/2019 Java.lang.String English

    9/39

    int offset,

    int count)

    Allocates a newStringthat contains characters from a subarray of the characterarray argument. Theoffsetargument is the index of the first character of thesubarray and thecountargument specifies the length of the subarray. The

    contents of the subarray are copied; subsequent modification of the characterarray does not affect the newly created string.Parameters:

    value- array that is the source of characters.offset- the initial offset.count- the length.

    Throws:IndexOutOfBoundsException- if theoffsetandcountarguments index charactersoutside the bounds of thevaluearray.

    String

    public String(byte[] ascii,int hibyte,

    int offset,

    int count)

    Deprecated.This method does not properly convert bytes into characters. Asof JDK 1.1, the preferred way to do this is via theStringconstructors that take

    a charset name or that use the platform's default charset.Allocates a newStringconstructed from a subarray of an array of 8-bit integer

    values.

    Theoffsetargument is the index of the first byte of the subarray, andthecountargument specifies the length of the subarray.

    Eachbytein the subarray is converted to acharas specified in the methodabove.

    Parameters:ascii- the bytes to be converted to characters.

    hibyte- the top 8 bits of each 16-bit Unicode character.offset- the initial offset.count- the length.

    Throws:IndexOutOfBoundsException- if theoffsetorcountargument is invalid.

    See Also:

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.html
  • 7/31/2019 Java.lang.String English

    10/39

    String(byte[], int),String(byte[], int, int,java.lang.String),String(byte[], int, int),String(byte[],java.lang.String),String(byte[])

    String

    public String(byte[] ascii,int hibyte)

    Deprecated.This method does not properly convert bytes into characters. Asof JDK 1.1, the preferred way to do this is via theStringconstructors that take

    a charset name or that use the platform's default charset.Allocates a newStringcontaining characters constructed from an array of 8-bitinteger values. Each charactercin the resulting string is constructed from thecorresponding componentbin the byte array such that:

    c == (char)(((hibyte & 0xff)

  • 7/31/2019 Java.lang.String English

    11/39

    length- the number of bytes to decodecharsetName- the name of a supportedcharset

    Throws:UnsupportedEncodingException- if the named charset is not supportedIndexOutOfBoundsException- if theoffsetandlengtharguments indexcharacters outside the bounds of thebytesarray

    Since:JDK1.1

    String

    public String(byte[] bytes,String charsetName)

    throwsUnsupportedEncodingException

    Constructs a newStringby decoding the specified array of bytes using thespecified charset. The length of the newStringis a function of the charset, andhence may not be equal to the length of the byte array.

    The behavior of this constructor when the given bytes are not valid in the givencharset is unspecified. TheCharsetDecoderclass should be used when morecontrol over the decoding process is required.

    Parameters:bytes- the bytes to be decoded into characterscharsetName- the name of a supportedcharset

    Throws:UnsupportedEncodingException- If the named charset is not supported

    Since:JDK1.1

    String

    public String(byte[] bytes,int offset,

    int length)

    Constructs a newStringby decoding the specified subarray of bytes using theplatform's default charset. The length of the newStringis a function of thecharset, and hence may not be equal to the length of the subarray.

    The behavior of this constructor when the given bytes are not valid in thedefault charset is unspecified. TheCharsetDecoderclass should be used whenmore control over the decoding process is required.

    http://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/Charset.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/Charset.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/Charset.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/UnsupportedEncodingException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/UnsupportedEncodingException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/UnsupportedEncodingException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/UnsupportedEncodingException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetDecoder.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetDecoder.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetDecoder.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/Charset.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/Charset.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/Charset.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/UnsupportedEncodingException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/UnsupportedEncodingException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetDecoder.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetDecoder.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetDecoder.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetDecoder.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/UnsupportedEncodingException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/Charset.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetDecoder.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/UnsupportedEncodingException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/UnsupportedEncodingException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/Charset.html
  • 7/31/2019 Java.lang.String English

    12/39

    Parameters:bytes- the bytes to be decoded into charactersoffset- the index of the first byte to decodelength- the number of bytes to decode

    Throws:IndexOutOfBoundsException- if theoffsetand thelengtharguments indexcharacters outside the bounds of thebytesarray

    Since:JDK1.1

    String

    public String(byte[] bytes)

    Constructs a newStringby decoding the specified array of bytes using the

    platform's default charset. The length of the newStringis a function of thecharset, and hence may not be equal to the length of the byte array.

    The behavior of this constructor when the given bytes are not valid in thedefault charset is unspecified. TheCharsetDecoderclass should be used whenmore control over the decoding process is required.

    Parameters:bytes- the bytes to be decoded into characters

    Since:

    JDK1.1

    String

    public String(StringBuffer buffer)

    Allocates a new string that contains the sequence of characters currentlycontained in the string buffer argument. The contents of the string buffer arecopied; subsequent modification of the string buffer does not affect the newlycreated string.

    Parameters:buffer- aStringBuffer.

    Method Detail

    length

    public int length()

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetDecoder.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetDecoder.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetDecoder.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/StringBuffer.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/StringBuffer.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/StringBuffer.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetDecoder.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.html
  • 7/31/2019 Java.lang.String English

    13/39

    Returns the length of this string. The length is equal to the number of 16-bitUnicode characters in the string.Specified by:lengthin interfaceCharSequenceReturns:the length of the sequence of characters represented by this object.

    charAt

    public char charAt(int index)

    Returns the character at the specified index. An index ranges from0tolength()- 1. The first character of the sequence is at index0, the next at index1, and soon, as for array indexing.Specified by:

    charAtin interfaceCharSequenceParameters:index- the index of the character.Returns:the character at the specified index of this string. The first character is atindex0.Throws:IndexOutOfBoundsException- if theindexargument is negative or not less thanthe length of this string.

    getChars

    public void getChars(int srcBegin,int srcEnd,

    char[] dst,

    int dstBegin)

    Copies characters from this string into the destination character array.

    The first character to be copied is at indexsrcBegin; the last character to becopied is at indexsrcEnd-1(thus the total number of characters to be copied

    issrcEnd-srcBegin). The characters are copied into the subarray ofdststartingat indexdstBeginand ending at index:

    dstbegin + (srcEnd-srcBegin) - 1

    Parameters:srcBegin- index of the first character in the string to copy.srcEnd- index after the last character in the string to copy.

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.html#length()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.html#length()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.html#charAt(int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.html#charAt(int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.html#charAt(int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.html#length()
  • 7/31/2019 Java.lang.String English

    14/39

    dst- the destination array.dstBegin- the start offset in the destination array.Throws:IndexOutOfBoundsException- If any of the following is true:

    srcBeginis negative. srcBeginis greater thansrcEnd srcEndis greater than the length of this string dstBeginis negative dstBegin+(srcEnd-srcBegin)is larger thandst.length

    getBytes

    public void getBytes(int srcBegin,int srcEnd,

    byte[] dst,

    int dstBegin)

    Deprecated.This method does not properly convert characters into bytes. Asof JDK 1.1, the preferred way to do this is via the thegetBytes()method, which

    uses the platform's default charset.Copies characters from this string into the destination byte array. Each bytereceives the 8 low-order bits of the corresponding character. The eight high-order bits of each character are not copied and do not participate in the transferin any way.

    The first character to be copied is at indexsrcBegin; the last character to becopied is at indexsrcEnd-1. The total number of characters to be copiedissrcEnd-srcBegin. The characters, converted to bytes, are copied into thesubarray ofdststarting at indexdstBeginand ending at index:

    dstbegin + (srcEnd-srcBegin) - 1

    Parameters:srcBegin- index of the first character in the string to copy.

    srcEnd- index after the last character in the string to copy.dst- the destination array.dstBegin- the start offset in the destination array.Throws:IndexOutOfBoundsException- if any of the following is true:

    srcBeginis negative

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.html
  • 7/31/2019 Java.lang.String English

    15/39

    srcBeginis greater thansrcEnd srcEndis greater than the length of this String dstBeginis negative dstBegin+(srcEnd-srcBegin)is larger thandst.length

    getBytes

    public byte[] getBytes(String charsetName)throwsUnsupportedEncodingException

    Encodes thisStringinto a sequence of bytes using the named charset, storingthe result into a new byte array.

    The behavior of this method when this string cannot be encoded in the givencharset is unspecified. TheCharsetEncoderclass should be used when morecontrol over the encoding process is required.

    Parameters:charsetName- the name of a supportedcharsetReturns:The resultant byte arrayThrows:UnsupportedEncodingException- If the named charset is not supportedSince:JDK1.1

    getBytes

    public byte[] getBytes()

    Encodes thisStringinto a sequence of bytes using the platform's defaultcharset, storing the result into a new byte array.

    The behavior of this method when this string cannot be encoded in the defaultcharset is unspecified. TheCharsetEncoderclass should be used when more

    control over the encoding process is required.

    Returns:The resultant byte arraySince:JDK1.1

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/UnsupportedEncodingException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/UnsupportedEncodingException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetEncoder.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetEncoder.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetEncoder.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/Charset.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/Charset.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/Charset.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/UnsupportedEncodingException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/UnsupportedEncodingException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetEncoder.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetEncoder.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetEncoder.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetEncoder.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/UnsupportedEncodingException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/Charset.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/nio/charset/CharsetEncoder.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/io/UnsupportedEncodingException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html
  • 7/31/2019 Java.lang.String English

    16/39

    equals

    public boolean equals(Object anObject)

    Compares this string to the specified object. The result istrueif and only if theargument is notnulland is aStringobject that represents the same sequence of

    characters as this object.Overrides:equalsin classObjectParameters:anObject- the object to compare thisStringagainst.Returns:trueif theString are equal;falseotherwise.See Also:compareTo(java.lang.String),equalsIgnoreCase(java.lang.String)

    contentEquals

    public boolean contentEquals(StringBuffer sb)

    Returnstrueif and only if thisStringrepresents the same sequence ofcharacters as the specifiedStringBuffer.Parameters:sb- theStringBufferto compare to.Returns:trueif and only if thisStringrepresents the same sequence of characters as the

    specifiedStringBuffer, otherwisefalse.Since:1.4

    equalsIgnoreCase

    public boolean equalsIgnoreCase(String anotherString)

    Compares thisStringto anotherString, ignoring case considerations. Twostrings are considered equal ignoring case if they are of the same length, andcorresponding characters in the two strings are equal ignoring case.

    Two charactersc1andc2are considered the same, ignoring case if at least oneof the following is true:

    The two characters are the same (as compared by the==operator). Applying the methodCharacter.toUpperCase(char)to each character

    produces the same result.

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#compareTo(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#compareTo(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equalsIgnoreCase(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equalsIgnoreCase(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equalsIgnoreCase(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/StringBuffer.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/StringBuffer.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html#toUpperCase(char)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html#toUpperCase(char)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html#toUpperCase(char)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html#toUpperCase(char)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/StringBuffer.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equalsIgnoreCase(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#compareTo(java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html
  • 7/31/2019 Java.lang.String English

    17/39

    Applying the methodCharacter.toLowerCase(char)to each characterproduces the same result.

    Parameters:anotherString- theStringto compare thisStringagainst.Returns:trueif the argument is notnulland theStrings are equal, ignoringcase;falseotherwise.See Also:equals(Object),Character.toLowerCase(char),Character.toUpperCase(char)

    compareTo

    public int compareTo(String anotherString)

    Compares two strings lexicographically. The comparison is based on theUnicode value of each character in the strings. The character sequencerepresented by thisStringobject is compared lexicographically to the charactersequence represented by the argument string. The result is a negative integer ifthisStringobject lexicographically precedes the argument string. The result isa positive integer if thisStringobject lexicographically follows the argumentstring. The result is zero if the strings are equal;compareToreturns0exactlywhen theequals(Object)method would returntrue.

    This is the definition of lexicographic ordering. If two strings are different, then

    either they have different characters at some index that is a valid index for bothstrings, or their lengths are different, or both. If they have different characters atone or more index positions, letkbe the smallest such index; then the stringwhose character at positionkhas the smaller value, as determined by using the< operator, lexicographically precedes the other string. In thiscase,compareToreturns the difference of the two character values atpositionkin the two string -- that is, the value:

    this.charAt(k)-anotherString.charAt(k)

    If there is no index position at which they differ, then the shorter stringlexicographically precedes the longer string. In this case,compareToreturns thedifference of the lengths of the strings -- that is, the value:this.length()-anotherString.length()

    Parameters:anotherString- theStringto be compared.Returns:

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html#toLowerCase(char)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html#toLowerCase(char)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html#toLowerCase(char)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html#toLowerCase(char)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html#toLowerCase(char)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html#toLowerCase(char)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html#toUpperCase(char)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html#toUpperCase(char)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html#toUpperCase(char)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html#toUpperCase(char)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html#toLowerCase(char)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html#toLowerCase(char)
  • 7/31/2019 Java.lang.String English

    18/39

    the value0if the argument string is equal to this string; a value less than0ifthis string is lexicographically less than the string argument; and a value greaterthan0if this string is lexicographically greater than the string argument.

    compareTo

    public int compareTo(Object o)

    Compares this String to another Object. If the Object is a String, this functionbehaves likecompareTo(String). Otherwise, it throws aClassCastException(asStrings are comparable only to other Strings).Specified by:compareToin interfaceComparableParameters:o- theObjectto be compared.

    Returns:the value0if the argument is a string lexicographically equal to this string; avalue less than0if the argument is a string lexicographically greater than thisstring; and a value greater than0if the argument is a string lexicographicallyless than this string.Throws:ClassCastException- if the argument is not aString.Since:1.2See Also:Comparable

    compareToIgnoreCase

    public int compareToIgnoreCase(String str)

    Compares two strings lexicographically, ignoring case differences. This methodreturns an integer whose sign is that of callingcompareTowith normalizedversions of the strings where case differences have been eliminated bycallingCharacter.toLowerCase(Character.toUpperCase(character)) on eachcharacter.

    Note that this method doesnottake locale into account, and will result in anunsatisfactory ordering for certain locales. The java.text packageprovidescollatorsto allow locale-sensitive ordering.

    Parameters:str- theStringto be compared.

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Comparable.html#compareTo(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Comparable.html#compareTo(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Comparable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Comparable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Comparable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Comparable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Comparable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Comparable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Comparable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Comparable.html#compareTo(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html
  • 7/31/2019 Java.lang.String English

    19/39

    Returns:a negative integer, zero, or a positive integer as the the specified String isgreater than, equal to, or less than this String, ignoring case considerations.Since:1.2See Also:Collator.compare(String, String)

    regionMatches

    public boolean regionMatches(int toffset,String other,

    int ooffset,

    int len)

    Tests if two string regions are equal.

    A substring of thisStringobject is compared to a substring of the argumentother. The result is true if these substrings represent identical charactersequences. The substring of thisStringobject to be compared begins atindextoffsetand has lengthlen. The substring of other to be compared beginsat indexooffsetand has lengthlen. The result isfalseif and only if at leastone of the following is true:

    toffsetis negative. ooffsetis negative. toffset+lenis greater than the length of thisStringobject. ooffset+lenis greater than the length of the other argument. There is some nonnegative integerkless thanlensuch

    that:this.charAt(toffset+k) != other.charAt(ooffset+k)

    Parameters:toffset- the starting offset of the subregion in this string.other- the string argument.ooffset- the starting offset of the subregion in the string argument.len- the number of characters to compare.

    Returns:trueif the specified subregion of this string exactly matches the specifiedsubregion of the string argument;falseotherwise.

    regionMatches

    public boolean regionMatches(boolean ignoreCase,

    http://docs.oracle.com/javase/1.4.2/docs/api/java/text/Collator.html#compare(java.lang.String,%20java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/text/Collator.html#compare(java.lang.String,%20java.lang.String)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/text/Collator.html#compare(java.lang.String,%20java.lang.String)
  • 7/31/2019 Java.lang.String English

    20/39

    int toffset,

    String other,

    int ooffset,

    int len)

    Tests if two string regions are equal.

    A substring of thisStringobject is compared to a substring of theargumentother. The result istrueif these substrings represent charactersequences that are the same, ignoring case if and only ifignoreCaseis true. Thesubstring of thisStringobject to be compared begins at indextoffsetand haslengthlen. The substring ofotherto be compared begins at indexooffsetandhas lengthlen. The result isfalseif and only if at least one of the following istrue:

    toffsetis negative. ooffsetis negative. toffset+lenis greater than the length of thisStringobject. ooffset+lenis greater than the length of the other argument. ignoreCaseisfalseand there is some nonnegative integerkless

    thanlensuch that: this.charAt(toffset+k) != other.charAt(ooffset+k)

    ignoreCaseistrueand there is some nonnegative integerklessthanlensuch that:

    Character.toLowerCase(this.charAt(toffset+k)) != Character.toLowerCase(other.charAt(ooffset+k))

    and:

    Character.toUpperCase(this.charAt(toffset+k)) !=

    Character.toUpperCase(other.charAt(ooffset+k))

    Parameters:ignoreCase- iftrue, ignore case when comparing characters.toffset- the starting offset of the subregion in this string.other- the string argument.ooffset- the starting offset of the subregion in the string argument.len- the number of characters to compare.Returns:trueif the specified subregion of this string matches the specified subregion ofthe string argument;falseotherwise. Whether the matching is exact or caseinsensitive depends on theignoreCaseargument.

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html
  • 7/31/2019 Java.lang.String English

    21/39

    startsWith

    public boolean startsWith(String prefix,int toffset)

    Tests if this string starts with the specified prefix beginning a specified index.

    Parameters:prefix- the prefix.toffset- where to begin looking in the string.Returns:trueif the character sequence represented by the argument is a prefix of thesubstring of this object starting at indextoffset;falseotherwise. The resultisfalseiftoffsetis negative or greater than the length of thisStringobject;otherwise the result is the same as the result of the expression

    this.subString(toffset).startsWith(prefix)

    startsWith

    public boolean startsWith(String prefix)

    Tests if this string starts with the specified prefix.Parameters:prefix- the prefix.Returns:trueif the character sequence represented by the argument is a prefix of thecharacter sequence represented by this string;falseotherwise. Note also

    thattruewill be returned if the argument is an empty string or is equal tothisStringobject as determined by theequals(Object)method.Since:1. 0

    endsWith

    public boolean endsWith(String suffix)

    Tests if this string ends with the specified suffix.Parameters:suffix- the suffix.Returns:trueif the character sequence represented by the argument is a suffix of thecharacter sequence represented by this object;falseotherwise. Note that theresult will betrueif the argument is the empty string or is equal tothisStringobject as determined by theequals(Object)method.

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html
  • 7/31/2019 Java.lang.String English

    22/39

    hashCode

    public int hashCode()

    Returns a hash code for this string. The hash code for aStringobject iscomputed as

    s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]

    usingintarithmetic, wheres[i]is theith character of the string,nis the lengthof the string, and^indicates exponentiation. (The hash value of the emptystring is zero.)Overrides:hashCodein classObjectReturns:a hash code value for this object.See Also:Object.equals(java.lang.Object)

    ,Hashtable

    indexOf

    public int indexOf(int ch)

    Returns the index within this string of the first occurrence of the specifiedcharacter. If a character with valuechoccurs in the character sequencerepresented by thisStringobject, then the index of the first such occurrence isreturned -- that is, the smallest valueksuch that:this.charAt(k) == ch

    istrue. If no such character occurs in this string, then-1is returned.Parameters:ch- a character.Returns:the index of the first occurrence of the character in the character sequencerepresented by this object, or-1if the character does not occur.

    indexOf

    public int indexOf(int ch,int fromIndex)

    Returns the index within this string of the first occurrence of the specifiedcharacter, starting the search at the specified index.

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#hashCode()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#hashCode()http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Hashtable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/Hashtable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/Hashtable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/Hashtable.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#equals(java.lang.Object)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#hashCode()
  • 7/31/2019 Java.lang.String English

    23/39

    If a character with valuechoccurs in the character sequence represented bythisStringobject at an index no smaller thanfromIndex, then the index of thefirst such occurrence is returned--that is, the smallest valueksuch that:

    (this.charAt(k) == ch) && (k >= fromIndex)

    is true. If no such character occurs in this string at or after positionfromIndex,then-1is returned.

    There is no restriction on the value offromIndex. If it is negative, it has thesame effect as if it were zero: this entire string may be searched. If it is greaterthan the length of this string, it has the same effect as if it were equal to thelength of this string:-1is returned.

    Parameters:ch- a character.fromIndex- the index to start the search from.Returns:the index of the first occurrence of the character in the character sequencerepresented by this object that is greater than or equal tofromIndex, or-1if thecharacter does not occur.

    lastIndexOf

    public intlastIndexOf

    (int ch)

    Returns the index within this string of the last occurrence of the specifiedcharacter. That is, the index returned is the largest valueksuch that:this.charAt(k) == ch

    is true. The String is searched backwards starting at the last character.Parameters:ch- a character.Returns:the index of the last occurrence of the character in the character sequencerepresented by this object, or-1if the character does not occur.

    lastIndexOf

    public int lastIndexOf(int ch,int fromIndex)

  • 7/31/2019 Java.lang.String English

    24/39

    Returns the index within this string of the last occurrence of the specifiedcharacter, searching backward starting at the specified index. That is, the indexreturned is the largest valueksuch that:this.charAt(k) == ch) && (k = Math.min(fromIndex, str.length()) && this.startsWith(str, k)

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html
  • 7/31/2019 Java.lang.String English

    25/39

    If no such value ofkexists, then -1 is returned.Parameters:str- the substring for which to search.fromIndex- the index from which to start the search.Returns:the index within this string of the first occurrence of the specified substring,starting at the specified index.

    lastIndexOf

    public int lastIndexOf(String str)

    Returns the index within this string of the rightmost occurrence of the specifiedsubstring. The rightmost empty string "" is considered to occur at the indexvaluethis.length(). The returned index is the largest valueksuch that

    this.startsWith(str, k)

    is true.Parameters:str- the substring to search for.Returns:if the string argument occurs one or more times as a substring within thisobject, then the index of the first character of the last such substring is returned.If it does not occur as a substring,-1is returned.

    lastIndexOf

    public int lastIndexOf(String str,int fromIndex)

    Returns the index within this string of the last occurrence of the specifiedsubstring, searching backward starting at the specified index. The integerreturned is the largest valueksuch that:

    k

  • 7/31/2019 Java.lang.String English

    26/39

    publicStringsubstring(int beginIndex)

    Returns a new string that is a substring of this string. The substring begins withthe character at the specified index and extends to the end of this string.

    Examples:

    "unhappy".substring(2) returns "happy"

    "Harbison".substring(3) returns "bison"

    "emptiness".substring(9) returns "" (an empty string)

    Parameters:beginIndex- the beginning index, inclusive.Returns:the specified substring.Throws:IndexOutOfBoundsException- ifbeginIndexis negative or larger than the length

    of thisStringobject.

    substring

    publicStringsubstring(int beginIndex,int endIndex)

    Returns a new string that is a substring of this string. The substring begins atthe specifiedbeginIndexand extends to the character at indexendIndex - 1.Thus the length of the substring isendIndex-beginIndex.

    Examples:

    "hamburger".substring(4, 8) returns "urge"

    "smiles".substring(1, 5) returns "mile"

    Parameters:beginIndex- the beginning index, inclusive.endIndex- the ending index, exclusive.Returns:the specified substring.

    Throws:IndexOutOfBoundsException- if thebeginIndexis negative, orendIndexis largerthan the length of thisStringobject, orbeginIndexis larger thanendIndex.

    subSequence

    publicCharSequencesubSequence(int beginIndex,

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html
  • 7/31/2019 Java.lang.String English

    27/39

    int endIndex)

    Returns a new character sequence that is a subsequence of this sequence.

    An invocation of this method of the form

    str.subSequence(begin, end)

    behaves in exactly the same way as the invocationstr.substring(begin, end)

    This method is defined so that theStringclass can implementtheCharSequenceinterface.Specified by:subSequencein interfaceCharSequenceParameters:beginIndex- the begin index, inclusive.endIndex- the end index, exclusive.

    Returns:the specified subsequence.Throws:IndexOutOfBoundsException- ifbeginIndexorendIndexare negative,ifendIndexis greater thanlength(), or ifbeginIndexis greater thanstartIndexSince:1.4

    concat

    publicStringconcat(String str)

    Concatenates the specified string to the end of this string.

    If the length of the argument string is0, then thisStringobject is returned.Otherwise, a newStringobject is created, representing a character sequencethat is the concatenation of the character sequence represented bythisStringobject and the character sequence represented by the argumentstring.

    Examples:

    "cares".concat("s") returns "caress"

    "to".concat("get").concat("her") returns "together"

    Parameters:str- theStringthat is concatenated to the end of thisString.Returns:

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.html#subSequence(int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.html#subSequence(int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/IndexOutOfBoundsException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.html#subSequence(int,%20int)http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.html
  • 7/31/2019 Java.lang.String English

    28/39

    a string that represents the concatenation of this object's characters followed bythe string argument's characters.

    replace

    publicStringreplace(char oldChar,char newChar)

    Returns a new string resulting from replacing all occurrences ofoldCharin thisstring withnewChar.

    If the characteroldChardoes not occur in the character sequence represented bythisStringobject, then a reference to thisStringobject is returned. Otherwise,a newStringobject is created that represents a character sequence identical tothe character sequence represented by thisStringobject, except that every

    occurrence ofoldChar

    is replaced by an occurrence ofnewChar

    .Examples:

    "mesquite in your cellar".replace('e', 'o')

    returns "mosquito in your collar"

    "the war of baronets".replace('r', 'y')

    returns "the way of bayonets"

    "sparring with a purple porpoise".replace('p', 't')

    returns "starring with a turtle tortoise"

    "JonL".replace('q', 'x') returns "JonL" (no change)

    Parameters:oldChar- the old character.newChar- the new character.Returns:a string derived from this string by replacing every occurrenceofoldCharwithnewChar.

    matches

    public boolean matches(String regex)

    Tells whether or not this string matches the givenregular expression.

    An invocation of this method of the formstr.matches(regex)yields exactly thesame result as the expression

    Pattern.matches(regex,str)

    Parameters:

    http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#matches(java.lang.String,%20java.lang.CharSequence)http://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#matches(java.lang.String,%20java.lang.CharSequence)http://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#matches(java.lang.String,%20java.lang.CharSequence)http://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sumhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html
  • 7/31/2019 Java.lang.String English

    29/39

    regex- the regular expression to which this string is to be matchedReturns:trueif, and only if, this string matches the given regular expressionThrows:PatternSyntaxException- if the regular expression's syntax is invalidSince:1.4See Also:Pattern

    replaceFirst

    publicStringreplaceFirst(String regex,String replacement)

    Replaces the first substring of this string that matches the givenregularexpressionwith the given replacement.

    An invocation of this method of the formstr.replaceFirst(regex,repl)yieldsexactly the same result as the expression

    Pattern.compile(regex).matcher(str).replaceFirst(repl)

    Parameters:regex- the regular expression to which this string is to be matchedReturns:

    The resultingStringThrows:PatternSyntaxException- if the regular expression's syntax is invalidSince:1.4See Also:Pattern

    replaceAll

    publicStringreplaceAll(String regex,String replacement)

    Replaces each substring of this string that matches the givenregularexpressionwith the given replacement.

    An invocation of this method of the formstr.replaceAll(regex,repl)yieldsexactly the same result as the expression

    http://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/PatternSyntaxException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/PatternSyntaxException.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.htmlhttp://docs.or

Recommended