Use Locale.filter method to filter locale - Java Internationalization

Java examples for Internationalization:Locale

Description

Use Locale.filter method to filter locale

Demo Code

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();
    List<Locale.LanguageRange> list1 = Locale.LanguageRange.parse(localeTags);
    list1.stream().forEach((range) -> {
      System.out.println("Range:" + range.getRange());
    });/*from   w  w w .ja va2 s  .com*/
    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);
    });
  }

}

Related Tutorials