How To List Down Countries In Java

java countries
Java is something what really impressed me than other programming languages anyways today we'll see how to list down all the countries and their country code . I don't know whether you know theres a small library called Locale in java.util namspace so that's what i am using here to do the thing .

import java.util.*;
 /* Author : Mohamed Shimran
    Blog :
class Countries {
    public static void main(String args[]) {
    String[] cntry = Locale.getISOCountries();
 for (String countryCode : cntry) {
  Locale obj = new Locale("", countryCode);
  System.out.println("Country Code = " + obj.getCountry() 
   + ", Country Name = " + obj.getDisplayCountry());
NOTE: i was using public class but i had to remove it because my class thingy goes mad still it works actually public class is not needed.
Okay , first we are importing the whole java utilities then we have a String array called cntry that's equivalent ISOCountries after that we have a for loop inside that we have assigned a objective and then finally we are printing the countries and the codes.

Let me run the program
OHH GOD , it seems the command prompt is not enough . so i tried eclipse console and i am now able to see them all
countries jdk7
Thank you for reading ! peace !

Post a Comment

Note: Only a member of this blog may post a comment.