views:

286

answers:

4

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
Although 'toUpperCase' will give the opposite effect, I'll still give you +1 :-)
Fortega
Fixed (including linking to Java6 docs - does anyone even still use 1.4?) and upvoted.
paxdiablo
@Fortega - the OP said "converting between" not "converting from / to". Converting between implies converting in both directions.
Stephen C
+2  A: 

String#toLowerCase

Fortega
+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
Yup. I recently discovered that the size of string is not always the same as the size of string.toUpperCase()
Fortega
Yes but only in those weird languages with umlauts and Eszett and names like Thorbjørn :-)
paxdiablo
you mean like weird languages like every other language on the planet?
jim
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
+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