Skip to content

Instantly share code, notes, and snippets.

@nelanka
Last active August 29, 2015 14:19
Show Gist options
  • Save nelanka/d4f94de3d0a3cc69f1f3 to your computer and use it in GitHub Desktop.
Save nelanka/d4f94de3d0a3cc69f1f3 to your computer and use it in GitHub Desktop.
Country Codes
import java.util.Locale
lazy val countryNameToCode = Locale.getISOCountries.map{ countryCode =>
(new Locale("", countryCode).getDisplayCountry, countryCode)
}.toMap
lazy val countryCodeToName = countryNameToCode.map(_.swap)
countryCodeToName("HK")
countryCodeToName("GB")
countryCodeToName("US")
countryCodeToName("ZA")
countryNameToCode("Hong Kong")
countryNameToCode("United Kingdom")
countryNameToCode("United States")
countryNameToCode("South Africa")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment