Search code examples
javalocale

How do I get all available locales in spanish using Java?


I do know how to get a list of all available locales in english using the method getAvailableLocales() of the class SimpleDateFormat in Java. But I want to get it in spanish.


Solution

  • I'm not sure, but it seems that you want to get all locales in Spanish language. It can be made as:

        Locale.setDefault(new Locale("ES"));
        Locale[] locales = SimpleDateFormat.getAvailableLocales();
        for(Locale l : locales) {
            System.out.println(l.getDisplayName());
        }
    

    At first you have to set default locale to Spanish and get all locales.