code: public static Locale parseLocale(String locale, String variant) {
  
          String language;
          String country;
          int index;
  
          if (((index = locale.indexOf(HYPHEN)) > -1) || ((index = locale.indexOf(UNDERSCORE)) > -1)) {
              if (index == 0) {
                  throw new IllegalArgumentException(Resources.getMessage("LOCALE_NO_LANGUAGE"));
              } else if (index == locale.length() - 1) {
                  throw new IllegalArgumentException(Resources.getMessage("LOCALE_EMPTY_COUNTRY"));
              }
              language = locale.substring(0, index);
              country = locale.substring(index + 1);
          } else {
              language = locale;
              country = "";
          }
  
          if (variant != null) {
              return new Locale(language, country, variant);
          } else {
              return new Locale(language, country);
          }
      }
docs: Parses the given locale string into its language and (optionally)
  country components, and returns the corresponding {@link Locale} object.
  
  @param locale  the locale string to parse; must not be null or empty
  @param variant the variant
  @return the specified Locale
  @throws IllegalArgumentException if the given locale does not have a
  language component or has an empty country component