What is the method for converting strings in Java between upper and lower case?
+7
A:
String#toLowerCase and String#toUpperCase are the methods you need.
PeterMmm
2009-12-23 10:09:25
Although 'toUpperCase' will give the opposite effect, I'll still give you +1 :-)
Fortega
2009-12-23 10:11:25
Fixed (including linking to Java6 docs - does anyone even still use 1.4?) and upvoted.
paxdiablo
2009-12-23 10:38:20
@Fortega - the OP said "converting between" not "converting from / to". Converting between implies converting in both directions.
Stephen C
2009-12-23 12:29:53
+3
A:
Yes. There are methods on the String itself for this.
Note that the result depends on the Locale the JVM is using. Beware, locales is an art in itself.
Thorbjørn Ravn Andersen
2009-12-23 10:15:14
Yup. I recently discovered that the size of string is not always the same as the size of string.toUpperCase()
Fortega
2009-12-23 10:19:12
Yes but only in those weird languages with umlauts and Eszett and names like Thorbjørn :-)
paxdiablo
2009-12-23 10:33:59
Actually we use ISØ-Låtin-1 here in Sĉändïñävïä so it could be a LØT WØRSË :)
Thorbjørn Ravn Andersen
2009-12-23 11:55:05
+1
A:
Hi,
There are methods in the String class; toUppercase()
and toLowerCase()
.
i.e.
String input = "Cricket!";
String upper = input.toUpperCase(); //stores "CRICKET!"
String lower = input.toLowerCase(); //stores "cricket!"
This will clarify your doubt
Crickey
2009-12-23 11:34:31