Table 4. Methods in the Class String
length() returns length of string object String variable = "physics";

variable.length() returns 7
toLowerCase() all characters in string object converted to lower case String variable = "PHYSICS";
variable.toLowerCase() returns "physics"
toUpperCase() all characters converted to upper case String variable = "physics";
variable.toLowerCase() returns "PHYSICS"
trim() leading and trailing blank space removed String variable = " stp ";
variable.trim() returns "stp"
charAt(Position) returns character in string at the Position. Positions are 0, 1,2, ... String variable = "physics";
variable.charAt(0) returns "p"
substring(Start) returns substring starting from Start to end of string object String example = "abcdef";
example.substring(2) returns "cdef"
substring(Start,End) returns substring from position Start up to, but not including, End of string object. String example = "abcdef";
example.substring(2,4) returns "cde"

Please send comments and corrections to Jan Tobochnik, jant@kzoo.edu or Harvey Gould, hgould@physics.clarku.edu.

Updated 7 January 2000.