Java Reference
In-Depth Information
Display 1.4
Some Methods in the Class String (part 2 of 4)
String toLowerCase( )
Returns a string with the same characters as the calling object string, but with all letter characters
converted to lowercase.
EXAMPLE
After program executes String greeting = "Hi Mary!";
greeting.toLowerCase() returns "hi mary!" .
String toUpperCase( )
Returns a string with the same characters as the calling object string, but with all letter characters
converted to uppercase.
EXAMPLE
After program executes String greeting = "Hi Mary!";
greeting.toUpperCase() returns "HI MARY!" .
String trim( )
Returns a string with the same characters as the calling object string, but with leading and trailing
white space removed. White space characters are the characters that print as white space on
paper, such as the blank (space) character, the tab character, and the new-line character '\n' .
EXAMPLE
After program executes String pause = " Hmm ";
pause.trim() returns "Hmm" .
char charAt ( 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' .
String substring ( Start )
Returns the substring of the calling object string starting from Start through to the end of the
calling object. Positions are counted 0, 1, 2, etc. Be sure to notice that the character at position
Start is included in the value returned.
EXAMPLE
After program executes String sample = "AbcdefG";
sample.substring(2) returns "cdefG" .
(continued)
 
Search WWH ::




Custom Search