Best code examples for Java 8 Locale class (java.util.Locale)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Locale class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Java 8 Locale examples from Open Source projects
This code example shows how to use the following methods: getCountry, getDisplayCountry, getDisplayLanguage, getDisplayName, getISO3Country
    /** 
     * helper method to display Locale info 
     */ 
    private static void printLocale(Locale loc) {
        System.out.println();
        System.out.println(loc.getDisplayName());
        System.out.println(loc.getCountry());
        System.out.println(loc.getLanguage());
        System.out.println(loc.getDisplayCountry());
        System.out.println(loc.getDisplayLanguage());
        System.out.println(loc.getDisplayName());
        System.out.println(loc.getISO3Country());
        System.out.println(loc.getISO3Language());
    } 
} 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getCountry, getLanguage
 
  @Test(dependsOnMethods = { "testDbOpenWithBackSlash" }) 
  public void testChangeLocale() throws IOException { 
    database = new OObjectDatabaseTx(url);
    database.open("admin", "admin");
    database.getStorage().getConfiguration().setLocaleLanguage(Locale.ENGLISH.getLanguage());
    database.getStorage().getConfiguration().setLocaleCountry(Locale.ENGLISH.getCountry());
    database.getStorage().getConfiguration().update();
    database.close();
  } 
 
  @Test(dependsOnMethods = { "testChangeLocale" }) 
  public void testRoles() throws IOException { 
    database = new OObjectDatabaseTx(url);
    database.open("admin", "admin");
    database.query(new OSQLSynchQuery<ORole>("select from ORole where name = 'admin'"));
    database.close();
  } 
 
  @Test(dependsOnMethods = { "testChangeLocale" }) 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setDefault
            input.close();
        } 
    } 
 
    private void setLocale(String code) {
        Locale locale = new Locale(code);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        mResources.updateConfiguration(config, mResources.getDisplayMetrics());
    } 
 
    private void assertResource(int resId, boolean ewo, boolean ew) throws Throwable {
        boolean expected = mWithOverlay ? ew : ewo;
        boolean actual = mResources.getBoolean(resId);
        assertEquals(expected, actual);
    } 
 
    private void assertResource(int resId, String ewo, String ew) throws Throwable {
        String expected = mWithOverlay ? ew : ewo;
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getCountry, getLanguage, getVariant
	 *  
	 * @param locale the locale for which a resource bundle is desired 
	 * @return a <code>List</code> of candidate <code>Locale</code>s for the given <code>locale</code> 
	 * @exception NullPointerException if <code>locale</code> is <code>null</code> */ 
	private static List<Locale> getCandidateLocales (Locale locale) {
		String language = locale.getLanguage();
		String country = locale.getCountry();
		String variant = locale.getVariant();
 
		List<Locale> locales = new ArrayList<Locale>(4);
		if (variant.length() > 0) {
			locales.add(locale);
		} 
		if (country.length() > 0) {
			locales.add((locales.size() == 0) ? locale : new Locale(language, country));
		} 
		if (language.length() > 0) {
			locales.add((locales.size() == 0) ? locale : new Locale(language));
		} 
		locales.add(Locale.ROOT);

7
CodeRank
This code example shows how to use the following methods: getCountry, getDisplayCountry, getDisplayLanguage, getDisplayName, getDisplayVariant
import java.util.MissingResourceException; 
 
public class LocaleTest extends junit.framework.TestCase {
    // http://b/2611311; if there's no display language/country/variant, use the raw codes. 
    public void test_getDisplayName_invalid() throws Exception { 
        Locale invalid = new Locale("AaBbCc", "DdEeFf", "GgHhIi");
 
        assertEquals("aabbcc", invalid.getLanguage());
        assertEquals("DDEEFF", invalid.getCountry());
        assertEquals("GgHhIi", invalid.getVariant());
 
        // Android using icu4c < 49.2 returned empty strings for display language, country, 
        // and variant, but a display name made up of the raw strings. 
        // Newer releases return slightly different results, but no less unreasonable. 
        assertEquals("aabbcc", invalid.getDisplayLanguage());
        assertEquals("", invalid.getDisplayCountry());
        assertEquals("DDEEFF_GGHHII", invalid.getDisplayVariant());
        assertEquals("aabbcc (DDEEFF,DDEEFF_GGHHII)", invalid.getDisplayName());
    } 
 

7
CodeRank
Related Java 8 Locale Questions & Answers:
See Code Examples for Java 8 Locale Methods: