Thursday, June 3, 2010

Have you aware of the problems using toUpperCase and toLowerCase method's in Java String API?

The toUpperCase() and toLowerCase() method's in String API's internally use the Locales. And hence these functions won't work with some of the locales (like turkish e.t.c).

For example consider the following toUpperCase() method code, it won't return the uppercase of the specified string value. To avoid that, you need to explicitly set English locale to the toUpperCase() and toLowerCase() method's. Here turkish language has a problems with charecter "i", so it won't return the expected value.

public class TestAgain

{

public static void main (String[] args) {
Locale locale = new Locale("tr" , "TR");

Locale.setDefault(locale);
String val = "DeleteAllVersions";
val = val.toUpperCase(Locale.getDefault());

System.out.println("val:" + val);

}
}

No comments:

Post a Comment