Here you can find the source of sortLocales(final List
Parameter | Description |
---|---|
locales | a parameter |
public static final void sortLocales(final List<Locale> locales)
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 Martin Reiterer./*w w w .j av a 2s . c o m*/ * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * @author Martin Reiterer * @author Christian Behon * @author Pascal Essiembre * ******************************************************************************/ import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Locale; public class Main { private static final Comparator<Locale> LOCALE_COMPERATOR = new Comparator<Locale>() { @Override public int compare(final Locale localeOne, final Locale localeTwo) { return getDisplayName(localeOne).compareToIgnoreCase(getDisplayName(localeTwo)); } private String getDisplayName(final Locale locale) { String displayName; if (locale == null) { displayName = "Default"; } else { displayName = locale.getDisplayName(); } return displayName; } }; /** * Sort the Locales alphabetically. * Make sure the root Locale is first. * * @param locales */ public static final void sortLocales(final List<Locale> locales) { Collections.sort(locales, LOCALE_COMPERATOR); } }