How to make a Locale object using language and country arguments

Problem:

You want to create a representation of your user's language and country.

Solution:

A Java locale represents a unique language and country combination. You create a Locale by specifying an ISO 639 language code and ISO 3166-2 country code in the constructor.

To create a Locale representing the English language:

Locale locale = new Locale("en");

 

To create a Locale representing English as spoken in Great Britain:

Locale locale = new Locale("en","GB");

 

To create a Locale representing English as spoken in Japan using a POSIX variant:

Locale locale = new Locale("en",GB","POSIX");