Get Country Name by Country Code using Java
In this tutorial, I am attaching simple program about, How to get Country Name by Country Code using Java.
CountryNameByCode.java
package com.dineshkrish.utilities; import java.util.Locale; import java.util.Scanner; public class CountryNameByCode { public static String getCountryName(String countryCode) { String countryName = ""; // Validating the given Input if(countryCode != null && !countryCode.isEmpty()) { // Defining the Locale Object using Country Code Locale locale = new Locale("", countryCode); // Method to get Country Name countryName = locale.getDisplayName(); } else { System.out.println("Invalid Country Code is given !!!"); return ""; } return countryName; } public static void main(String[] args) { // Defining Scanner Object to read input from user Scanner scanner = new Scanner(System.in); System.out.println("Enter the Country Code : "); String countryCode = scanner.next(); <a href="https://docs.oracle.com/javase/7/docs/api/" target="_blank">Java API Documentaion</a> // Method Invocation String countryName = getCountryName(countryCode); System.out.println("Country Name : "+countryName); // Closing the scanner scanner.close(); } }
Output
—————
Enter the Country Code :
IN
Country Name : India
References
More from my site

Hello, folks, I am a founder of idineshkrishnan.com. I love open source technologies, If you find my tutorials are useful, please consider making donations to these charities.
No responses yet