Java Locale get language tag

Description

Java Locale get language tag

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public class Main {

   public static void main(String[] args) {
      String localeTags = Locale.ENGLISH.toLanguageTag() + "," + Locale.CANADA.toLanguageTag();
      /* w  ww  .j  av  a 2  s  .c  om*/
      List<Locale.LanguageRange> list1 = Locale.LanguageRange.parse(localeTags);
      list1.stream().forEach((range) -> {
         System.out.println("Range:" + range.getRange());
      });
      
      List<Locale> localeList = new ArrayList<>();
      localeList.add(new Locale("en"));
      localeList.add(new Locale("en-JP"));

      List<Locale> tags1 = Locale.filter(list1, localeList);
      System.out.println("The following is the matching list of Locales:");
      tags1.stream().forEach((tag) -> {
         System.out.println(tag);
      });
   }
}



PreviousNext

Related