Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import java.util.Locale;
import java.util.Collection;
import java.util.List;
import java.util.ArrayList;
public class LanguageTagFilteringExample {
public static void main(String[] args) {
String ranges = "en-US;q=1.0,en-GB;q=0.5,de-DE;q=0.0";
List<Locale.LanguageRange> languageRanges = Locale.LanguageRange.parse(ranges);
Collection<Locale> localesList = new ArrayList<>();
localesList.add(Locale.forLanguageTag("en-GB"));
localesList.add(Locale.forLanguageTag("en-US"));
localesList.add(Locale.forLanguageTag("ja-*"));
localesList.add(Locale.forLanguageTag("fe-FE"));
List<Locale> filteredSet = Locale.filter(languageRanges,localesList);
for(Locale locale : filteredSet){
System.out.println(locale.toString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.