code: @SuppressWarnings("All")
      public static Locale findOptimumLocale(final String language, final String country, final String variant) {
  
          final boolean hasCountry = country != null && !country.isEmpty();
          final boolean hasVariant = variant != null && !variant.isEmpty();
  
          final Locale[] availableLocales = Locale.getAvailableLocales();
          for (int i = 0; i < availableLocales.length; i++) {
  
              final Locale current = availableLocales[i];
  
              // Extract the language/country/variant of the current Locale.
              final String currentLanguage = current.getLanguage();
              final String currentCountry = current.getCountry();
              final String currentVariant = current.getVariant();
  
              // Check if the current Locale matches the supplied
              final boolean isLanguageMatch = language.equalsIgnoreCase(currentLanguage);
              final boolean isCountryMatch = (hasCountry && country.equalsIgnoreCase(currentCountry))
                      || (!hasCountry && (currentCountry == null || currentCountry.isEmpty()));
              final boolean isVariantMatch = (hasVariant && variant.equalsIgnoreCase(currentVariant))
                      || (!hasVariant && (currentVariant == null || currentVariant.isEmpty()));
  
              if (isLanguageMatch && isCountryMatch && isVariantMatch) {
                  return current;
              }
          }
  
          // Default to the default platform locale.
          return Locale.getDefault();
      }
docs: Helper method to find the best matching locale, implying a workaround for problematic
  case-sensitive Locale detection within the JDK. (C.f. Issue #112).
  
  @param language The given Language.
  @param country  The given Country. May be null or empty to indicate that the Locale returned should not
  contain a Country definition.
  @param variant  The given Variant. May be null or empty to indicate that the Locale returned should not
  contain a Variant definition.
  @return The optimally matching Locale.