img
String upper = s.toUpperCase();
String lower = s.toLowerCase();
System.out.println("Uppercase: " + upper);
System.out.println("Lowercase: " + lower);
}
}
The output produced by the program is shown here:
Original: This is a test.
Uppercase: THIS IS A TEST.
Lowercase: this is a test.
Additional String Methods
In addition to those methods discussed earlier, String includes several other methods. These
are summarized in the following table. Notice that many were added by J2SE 5.
Method
Description
int codePointAt(int i)
Returns the Unicode code point at the location specified by i.
Added by J2SE 5.
int codePointBefore(int i)
Returns the Unicode code point at the location that precedes
that specified by i. Added by J2SE 5.
int codePointCount(int star t, int end)
Returns the number of code points in the por tion of the invoking
String that are between star t and end­1. Added by J2SE 5.
boolean contains(CharSequence str)
Returns true if the invoking object contains the string specified
by str. Returns false, other wise. Added by J2SE 5.
boolean contentEquals(CharSequence str)
Returns true if the invoking string contains the same string as
str. Other wise, returns false. Added by J2SE 5.
boolean contentEquals(StringBuf fer str)
Returns true if the invoking string contains the same string as
str. Other wise, returns false.
static String format(String fmtstr,
Returns a string formatted as specified by fmtstr. (See Chapter 18
Object ... args)
for details on formatting.) Added by J2SE 5.
static String format(Locale loc,
Returns a string formatted as specified by fmtstr. Formatting
String fmtstr,
is governed by the locale specified by loc. (See Chapter 18 for
Object ... args)
details on formatting.) Added by J2SE 5.
boolean matches(string regExp)
Returns true if the invoking string matches the regular expression
passed in regExp. Other wise, returns false.
int of fsetByCodePoints(int star t, int num)
Returns the index with the invoking string that is num code points
beyond the star ting index specified by star t. Added by J2SE 5.
String
Returns a string in which the first substring that matches the
replaceFirst(String regExp,
regular expression specified by regExp is replaced by newStr.
String newStr)
String
Returns a string in which all substrings that match the regular
replaceAll(String regExp,
expression specified by regExp are replaced by newStr.
String newStr)
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home