1

I have code like this:

import java.util.Locale;
Locale locale = new Locale("en_US");

When I wrote:

System.out.println(locale.toString());

it returns

en_us

not

en_US

is any way to get case-sensitive value?

David Silva
  • 1,939
  • 7
  • 28
  • 60
  • Sergi's answer is correct: the language field is by definition case insensitive and the original case that you use is not stored. – herman Jan 07 '14 at 11:30
  • And if you still want, then do this _System.out.println(locale.toString().replace("us", "US"))_; Since you are passing the language code – gowtham Jan 07 '14 at 11:31

1 Answers1

2

Taken from Oracle: The language field is case insensitive, but Locale always canonicalizes to lower case.

Sergi
  • 579
  • 3
  • 14
  • 1
    @MarkoTopolnik No, it is the correct quote. The constructor with 1 `String` argument only has a language argument. Calling `getCountry()` will return null or empty string. – herman Jan 07 '14 at 11:28