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.

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.out.println("Enter the Country Code : ");
String countryCode =;
<a href="" target="_blank">Java API Documentaion</a>	
// Method Invocation
String countryName = getCountryName(countryCode);
System.out.println("Country Name : "+countryName);
// Closing the scanner 



Enter the Country Code :
Country Name : India


1. Java API Documentaion


No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *