You can do:
String val = "fr_US";
String[] tab = val.split("_");
Locale locale = new Locale(tab[0], tab[1]);
Or if you hard coded val
Locale locale = new Locale("fr", "US");
We also Localehave a method forLanguageTag, but as a parameter you must pass the BCP 47 language tag (s -, not _).
source
share