Java Reference
In-Depth Information
METHODS
public char charAt( int position)
Returns the character in the calling object string at the position. Positions are counted 0, 1, 2, etc.
EXAMPLE
After program executes String greeting = "Hello!";
greeting.charAt(0) returns 'H' , and
greeting.charAt(1) returns 'e' .
Throws:
IndexOutOfBoundsException if position is negative or not less than the length of the
calling object string.
public int compareTo(String aString)
Compares the calling object string and the string argument to see which comes fi rst in the
lexicographic ordering. Lexicographic order is the same as alphabetical order but with the
characters ordered as in Appendix 3. Note that in Appendix 3 all the uppercase letters are in
regular alphabetical order and all the lowercase letters are in alphabetical order, but all the
uppercase letters precede all the lowercase letters. So, lexicographic ordering is the same as
alphabetical ordering when either both strings are all uppercase letters or both strings are all
lowercase letters. If the calling string is fi rst, it returns a negative value. If the two strings are
equal, it returns zero. If the argument is fi rst, it returns a positive number.
EXAMPLE
After program executes String entry = "adventure";
entry.compareTo("zoo") returns a negative number,
entry.compareTo("adventure") returns 0 , and
entry.compareTo("above") returns a positive number.
Throws:
NullPointerException if aString is null.
public int compareToIgnoreCase(String aString)
Compares the calling object string and the string argument to see which comes fi rst in the
lexicographic ordering, treating upper- and lowercase letters as being the same. (To be precise,
all uppercase letters are treated as if they were their lowercase versions in doing the comparison.)
Thus, if both strings consist entirely of letters, the comparison is for ordinary alphabetical order.
If the calling string is fi rst, it returns a negative value. If the two strings are equal, ignoring cases,
it returns zero. If the argument is fi rst, it returns a positive number.
EXAMPLE
After program executes String entry = "adventure";
entry.compareToIgnoreCase("Zoo") returns a negative number,
entry.compareToIgnoreCase("Adventure") returns 0 , and
"Zoo".compareToIgnoreCase(entry) returns a positive number.
Throws:
NullPointerException if aString is null .
Search WWH ::




Custom Search