Java Reference
In-Depth Information
TABLE 3-1
Some Commonly Used
String
Methods (continued)
String substring(
int
beginIndex)
//Returns the string which is a substring of this string
//beginning at beginIndex until the end of the string.
//Example: sentence.substring(12) returns the string
//
"with Java"
String substring(
int
beginIndex,
int
endIndex)
//Returns the string which is a substring of this string
//beginning at beginIndex until endIndex - 1
String toLowerCase()
//Returns the string that is the same as this string, except
//that all uppercase letters of this string are replaced with
//their equivalent lowercase letters
//Example: sentence.toLowerCase() returns "programming with java"
String toUpperCase()
//Returns the string that is the same as this string, except
//that all lowercase letters of this string are replaced with
//their equivalent uppercase letters
//Example: sentence.toUpperCase() returns "PROGRAMMING WITH JAVA"
boolean
startsWith(String str)
//Returns true if the string begins with the string specified by str;
//otherwise, this methods returns false.
boolean
endsWith(String str)
//Returns true if the string ends with the string specified by str
//otherwise, this methods returns false.
boolean
regionMatches(
int
ind, String str,
int
strIndex,
int
len)
//Returns true if the substring of str starting at strIndex and length
//specified by len is same as the substring of this String
//object starting at ind and having the same length
boolean
regionMatches(
boolean
ignoreCase,
int
ind,
String str,
int
strIndex, int
len
)
//Returns true if the substring of str starting at strIndex and length
//specified by len is same as the substring of this String
//object starting at ind and having the same length. If ignoreCase
//is true, then during character comparison, case is ignored.
Table 3-1 lists only some of the methods for string manipulation. Moreover, the table gives
only the name of the method, the number of parameters, and the type of the method. The
reader can find a list of
String
methods at the Web site http://java.sun.com/javase/7/docs/
api/. The methods
equals
and
compareTo
are explained in Chapter 4 and the methods,
startsWith
,
endsWith
,and
regionMatches
are explained in Example 3-3.
Search WWH ::
Custom Search