- In current post, we will print /displays locales, country codes, country names and country languages.
- We will use Locale class to retrieve available locales.
- We will iterate through the locales using java 8 streams (and we will print the desired information).
Program – list locales, country codes/names/languages (java8 streams).
package org.learn; import java.util.Arrays; import java.util.Locale; public class ListLocales { public static void main(String[] args) { Locale[] locales = Locale.getAvailableLocales(); System.out.printf("%5s %10s %15s %20s\n","Locale", "CountryCode","Country", "Language"); Arrays.stream(locales) .filter(locale -> locale.toString().length() > 0). forEach( (locale) -> System.out.printf( "%5s - %10s - %20s - %20s\n", locale, locale.getCountry(), locale.getDisplayCountry(), locale.getDisplayLanguage() ) ); } }
Output- print locales, country codes/names/languages (java8 streams).
Locale CountryCode Country Language ar_AE - AE - United Arab Emirates - Arabic ar_JO - JO - Jordan - Arabic ar_SY - SY - Syria - Arabic hr_HR - HR - Croatia - Croatian fr_BE - BE - Belgium - French es_PA - PA - Panama - Spanish mt_MT - MT - Malta - Maltese es_VE - VE - Venezuela - Spanish bg - - - Bulgarian zh_TW - TW - Taiwan - Chinese it - - - Italian ko - - - Korean uk - - - Ukrainian lv - - - Latvian da_DK - DK - Denmark - Danish es_PR - PR - Puerto Rico - Spanish vi_VN - VN - Vietnam - Vietnamese en_US - US - United States - English sr_ME - ME - Montenegro - Serbian sv_SE - SE - Sweden - Swedish es_BO - BO - Bolivia - Spanish en_SG - SG - Singapore - English ar_BH - BH - Bahrain - Arabic pt - - - Portuguese ar_SA - SA - Saudi Arabia - Arabic sk - - - Slovak ar_YE - YE - Yemen - Arabic hi_IN - IN - India - Hindi ga - - - Irish en_MT - MT - Malta - English fi_FI - FI - Finland - Finnish et - - - Estonian sv - - - Swedish cs - - - Czech sr_BA_#Latn - BA - Bosnia and Herzegovina - Serbian el - - - Greek uk_UA - UA - Ukraine - Ukrainian hu - - - Hungarian fr_CH - CH - Switzerland - French in - - - Indonesian es_AR - AR - Argentina - Spanish ar_EG - EG - Egypt - Arabic ja_JP_JP_#u-ca-japanese-JP - Japan - Japanese es_SV - SV - El Salvador - Spanish pt_BR - BR - Brazil - Portuguese be - - - Belarusian is_IS - IS - Iceland - Icelandic cs_CZ - CZ - Czech Republic - Czech es - - - Spanish pl_PL - PL - Poland - Polish tr - - - Turkish ca_ES - ES - Spain - Catalan sr_CS - CS - Serbia and Montenegro - Serbian ms_MY - MY - Malaysia - Malay hr - - - Croatian lt - - - Lithuanian es_ES - ES - Spain - Spanish es_CO - CO - Colombia - Spanish bg_BG - BG - Bulgaria - Bulgarian sq - - - Albanian fr - - - French ja - - - Japanese sr_BA - BA - Bosnia and Herzegovina - Serbian is - - - Icelandic es_PY - PY - Paraguay - Spanish de - - - German es_EC - EC - Ecuador - Spanish es_US - US - United States - Spanish ar_SD - SD - Sudan - Arabic en - - - English ro_RO - RO - Romania - Romanian en_PH - PH - Philippines - English ca - - - Catalan ar_TN - TN - Tunisia - Arabic sr_ME_#Latn - ME - Montenegro - Serbian es_GT - GT - Guatemala - Spanish sl - - - Slovenian ko_KR - KR - South Korea - Korean el_CY - CY - Cyprus - Greek es_MX - MX - Mexico - Spanish ru_RU - RU - Russia - Russian es_HN - HN - Honduras - Spanish zh_HK - HK - Hong Kong - Chinese no_NO_NY - NO - Norway - Norwegian hu_HU - HU - Hungary - Hungarian th_TH - TH - Thailand - Thai ar_IQ - IQ - Iraq - Arabic es_CL - CL - Chile - Spanish fi - - - Finnish ar_MA - MA - Morocco - Arabic ga_IE - IE - Ireland - Irish mk - - - Macedonian tr_TR - TR - Turkey - Turkish et_EE - EE - Estonia - Estonian ar_QA - QA - Qatar - Arabic sr__#Latn - - - Serbian pt_PT - PT - Portugal - Portuguese fr_LU - LU - Luxembourg - French ar_OM - OM - Oman - Arabic th - - - Thai sq_AL - AL - Albania - Albanian es_DO - DO - Dominican Republic - Spanish es_CU - CU - Cuba - Spanish ar - - - Arabic ru - - - Russian en_NZ - NZ - New Zealand - English sr_RS - RS - Serbia - Serbian de_CH - CH - Switzerland - German es_UY - UY - Uruguay - Spanish ms - - - Malay el_GR - GR - Greece - Greek iw_IL - IL - Israel - Hebrew en_ZA - ZA - South Africa - English th_TH_TH_#u-nu-thai -TH - Thailand - Thai hi - - - Hindi fr_FR - FR - France - French de_AT - AT - Austria - German nl - - - Dutch no_NO - NO - Norway - Norwegian en_AU - AU - Australia - English vi - - - Vietnamese nl_NL - NL - Netherlands - Dutch fr_CA - CA - Canada - French lv_LV - LV - Latvia - Latvian de_LU - LU - Luxembourg - German es_CR - CR - Costa Rica - Spanish ar_KW - KW - Kuwait - Arabic sr - - - Serbian ar_LY - LY - Libya - Arabic mt - - - Maltese it_CH - CH - Switzerland - Italian da - - - Danish de_DE - DE - Germany - German ar_DZ - DZ - Algeria - Arabic sk_SK - SK - Slovakia - Slovak lt_LT - LT - Lithuania - Lithuanian it_IT - IT - Italy - Italian en_IE - IE - Ireland - English zh_SG - SG - Singapore - Chinese ro - - - Romanian en_CA - CA - Canada - English nl_BE - BE - Belgium - Dutch no - - - Norwegian pl - - - Polish zh_CN - CN - China - Chinese ja_JP - JP - Japan - Japanese de_GR - GR - Greece - German sr_RS_#Latn - RS - Serbia - Serbian iw - - - Hebrew en_IN - IN - India - English ar_LB - LB - Lebanon - Arabic es_NI - NI - Nicaragua - Spanish zh - - - Chinese mk_MK - MK - Macedonia - Macedonian be_BY - BY - Belarus - Belarusian sl_SI - SI - Slovenia - Slovenian es_PE - PE - Peru - Spanish in_ID - ID - Indonesia - Indonesian en_GB - GB - United Kingdom - English
Note: We have done some formatting in the program output.