6

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"));
Ashot Karakhanyan
  • 2,804
  • 3
  • 23
  • 28
abiieez
  • 3,139
  • 14
  • 57
  • 110

2 Answers2

9
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.

Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
1

try this:

docs.oracle.com/javase/tutorial/i18n/locale/create.html

System.out.println(Locale.forLanguageTag("en-US"));
user2886551
  • 112
  • 2