Suppose to have a two-characters String
, which should represent the ISO 639 country or language name.
You know, Locale
class has two functions getISOLanguages
and getISOCountries
that return an array of String
with all the ISO languages and ISO countries, respectively.
To check if a specific String
object is a valid ISO language or ISO country I should look inside that arrays for a matching String
. Ok, I can do that by using a binary search (e.g. Arrays.binarySearch
or the ApacheCommons ArrayUtils.contains
).
The question is: exists any utility (e.g. from Guava or Apache Commons libraries) that provides a cleaner way, e.g. a function that returns a boolean
to validate a String
as a valid ISO 639 language or ISO 639 Country?
For instance:
public static boolean isValidISOLanguage(String s)
public static boolean isValidISOCountry(String s)