Method prototype
|
Description |
Examples
str1="Hello"
str2 ="Everyone" |
| char charAt( int index ) Note: this does not give you a
String,
it gives you a char as it is called in
Java.
This is a single letter only. To use it as a
String you must convert it to a String.
Use this method:
char letter = 't';
String s;
s = String.valueOf( letter );
|
Returns the character at the specified index. |
str1.charAt( 1 ) = 'e'
Note the first character is zero. |
| int compareTo( String anotherString ) |
Compares two strings lexicographically. (Which comes first
"alphabetically" speaking.) If "this string" is before "that string", then the
result is negative, if "this string" goes after "that string", then the result is positive,
if they are the same then the result is zero. |
this string. compareTo ( that string )
str2.compareTo( str1 ) = -3
| Negative number means: |
| "Everyone" |
goes before |
"Hello" |
| str2 |
str1 |
| this string |
that string |
str1.compareTo( str2 ) = 3
| Positive number means: |
| "Hello" |
goes after |
"Everyone" |
| str1 |
str2 |
| this string |
that string |
|
| boolean equals( String str ) |
Compares the this string to the specified object. |
str1.equals( str2 ) = false
|
| boolean equalsIgnoreCase( String str ) |
Compares the this String to str, ignoring case considerations. |
str2.equalsIgnoreCase("EVERYONE") = true
|
| int length( ) |
Returns the length of the this string. |
str2.length( ) = 8 |
Version 1:
String substring(int beginIndex, int endIndex)
Version 2:
String substring( int beginIndex )
|
Returns a new string that is a substring of the this string.
Version 1 of the method:
The substring begins at the specified beginIndex and
extends to the character at index endIndex - 1. Thus the
length of the substring is endIndex-beginIndex.
Version 2 of the method:
The substring begins at the specified beginIndex and
extends to the end of the string.
|
Version 1:
str2.substring ( 1, 4 ) = "ver"
(That is, characters 1, 2, 3 of str2 go into the new
String.)
Version 2:
str2.substring ( 5 ) = "one"
|
| String toLowerCase( ) |
Converts all of the characters in the this String to lower case. |
str1.toLowerCase( ) = "hello" |
| String toUpperCase( ) |
Converts all of the characters in the this String to upper case. |
str1.toUpperCase( ) = "HELLO" |
| |
|
|