This appendix contains a subset of useful String methods.
(You do not have to import the String class because it is part
of a special package that is always automatically imported.)
Selected Methods from the String Class:
public int length()Returns the length of this string. Returns: the length of the sequence of characters represented by this objectpublic boolean isEmpty()Returnstrueif and only iflength()is 0. Returns:trueiflength()is 0,falseotherwisepublic boolean equals(Object anObject)Compares this string to the specified object. Parameters:anObject- The object to compare thisStringagainst Returns:trueif the given object represents aStringequivalent to this string,falseotherwisepublic boolean equalsIgnoreCase(String anotherString)Compares this String to another String, ignoring case considerations. Parameters:anotherString- TheStringto compare thisStringagainst Returns:trueif the argument is notnulland it represents an equivalentStringignoring case,falseotherwisepublic boolean contains(String str)Returnstrueif and only if this string contains the specified string. Parameters:str- theStringto search for Returns: true if this string containsstr,falseotherwisepublic boolean startsWith(String prefix)Tests if this string starts with the specified prefix. Parameters:prefix- the prefix Returns: true ifprefixis a prefix of this string,falseotherwise. Note also thattruewill be returned if the argument is an empty string or is equal to thisStringobject as determined by theequals(Object)method.public boolean endsWith(String suffix)Tests if this string ends with the specified suffix. Parameters:suffix- the suffix Returns: true ifsuffixis a suffix of this string,falseotherwise. Note that the result will betrueif the argument is an empty string or is equal to thisStringobject as determined by theequals(Object)method.public String toLowerCase()Converts all of the characters in thisStringto lower case. Returns: theString, converted to lowercasepublic String toUpperCase()Converts all of the characters in thisStringto upper case. Returns: theString, converted to uppercasepublic String concat(String str)Returns a new string representing this string followed by the specified string. This string is unchanged. Parameters:str- theStringthat is concatenated to the end of thisStringReturns: the combined, concatenated string