code: private static Locale findFormattingMatch(Locale pref, Locale[] avail) {
          Locale match = null;
          boolean langAndCountryMatch = false;
          for (Locale locale : avail) {
              if (pref.equals(locale)) {
                  // Exact match
                  match = locale;
                  break;
              } else if (
                      !"".equals(pref.getVariant()) &&
                              "".equals(locale.getVariant()) &&
                              pref.getLanguage().equals(locale.getLanguage()) &&
                              pref.getCountry().equals(locale.getCountry())) {
                  // Language and country match; different variant
                  match = locale;
                  langAndCountryMatch = true;
              } else if (
                      !langAndCountryMatch &&
                              pref.getLanguage().equals(locale.getLanguage()) &&
                              ("".equals(locale.getCountry()))) {
                  // Language match
                  if (match == null) {
                      match = locale;
                  }
              }
          }
          return match;
      }
docs: /*
  Returns the best match between the given preferred locale and the
  given available locales.
  
  The best match is given as the first available locale that exactly
  matches the given preferred locale ("exact match"). If no exact match
  exists, the best match is given to an available locale that meets
  the following criteria (in order of priority):
  - available locale's variant is empty and exact match for both
  language and country
  - available locale's variant and country are empty, and exact match
  for language.
  
  @param pref the preferred locale
  @param avail the available formatting locales
  
  @return Available locale that best matches the given preferred locale,
  or <tt>null</tt> if no match exists