java - Locale - two argument construct in action -


here's code snippet locale classes used 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; (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 constructor's second argument stands for. mentioned formatted dates aren't dependent on fact whether passed "country" argument constructor or not.

...so question is:

are there proper usecases two-argument locale constructor?

yes, there cases. locale not used dateformat, can use @ formatting currencies.

double amount =200.0; locale locale = new locale("es", "es");       numberformat currencyformatter = numberformat.getcurrencyinstance(locale); system.out.println(currencyformatter.format(amount));  locale = new locale("es", "cu");       currencyformatter = numberformat.getcurrencyinstance(locale); system.out.println(currencyformatter.format(amount)); 

in example locales spain , cuba defined , 200.00 formatted.

$ java helloworld  200,00 € cu$200,00 

as can see currency symbol , position of currency symbol changed.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -