Locale two argument construct in action

Here's my code snippet for Locale classes used for date formatting:

List<Locale> locales = new ArrayList<>(8);
locales.add(new Locale("en"));
locales.add(new Locale("pl"));
locales.add(new Locale("en", "PL"));
locales.add(new Locale("en", "CH"));
locales.add(new Locale("en", "BR"));
locales.add(new Locale("pl", "JP"));
locales.add(new Locale("pl", "GER"));
locales.add(new Locale("pl", "DK"));
DateFormat dateInstance;
for (Locale locale : locales) {
    dateInstance = DateFormat.getDateInstance(DateFormat.FULL, locale);
    System.out.println(dateInstance.format(date));
}

I got following output:

Tuesday, April 19, 2016
wtorek, 19 kwietnia 2016
Tuesday, April 19, 2016
Tuesday, April 19, 2016
Tuesday, April 19, 2016
wtorek, 19 kwietnia 2016
wtorek, 19 kwietnia 2016
wtorek, 19 kwietnia 2016

I can't understand what for the constructor's second argument stands for. Mentioned formatted dates aren't dependent on the fact whether I passed the "Country" argument to constructor or not.

...so my question is:

Are there any proper usecases for two-argument Locale constructor?

Jon Skeet
people
quotationmark

You happen to have picked countries which all have the same format. However, that's not always the case. Here's a different example:

import java.util.*;
import java.text.*;

class Test {    
    public static void main(String[] args) {
        List<Locale> locales = new ArrayList<>(8);
        locales.add(new Locale("en"));
        locales.add(new Locale("en", "GB"));
        locales.add(new Locale("en", "US"));
        Date date = new Date();
        for (Locale locale : locales) {
            DateFormat dateInstance = DateFormat.getDateInstance(DateFormat.FULL, locale);
            System.out.println(dateInstance.format(date));
        }
    }
}

Output:

Tuesday, April 19, 2016
Tuesday, 19 April 2016
Tuesday, April 19, 2016

Note how the second line is different to the third. That basically shows that the UK-English date format is different to the US-English date format.

I also spotted that the countries you passed in aren't ones which are traditionally associated with the language you've specified - there's no "Polish English" or "Swiss English" whereas there definitely is a "UK English" vs "US English" (and likewise Canadian English, Australian English etc).

If you pass in a country where the specified language is one of the primary ones spoken in that country, you're more likely to get country-specific results.

people

See more on this question at Stackoverflow