Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Locale case sensitivity

I have the following code to display current locale

System.out.println(Locale.getDefault());
System.out.println(new Locale("en_US"));

The above gives output as follows

en_US
en_us

How do I construct a Locale instance which gives en_US ?

EDIT

I am asking this because my resources which is Messages_en_US.properties is being ignored when I try to set it as default locale if any exception occurs during

ResourceBundle.getBundle("Messages", new Locale("en_US"));
like image 390
abiieez Avatar asked Feb 18 '14 16:02

abiieez


1 Answers

new Locale("en_US")

is a Locale whose language code is "en_us".

new Locale("en", "US")

is a locale whose language code is "en", and whose country code is "US".

The javadoc says of the single-argument constructor:

Locale

public Locale(String language)

Construct a locale from a language code. This constructor normalizes the language value to lowercase.

like image 173
Mike Samuel Avatar answered Oct 23 '22 19:10

Mike Samuel