Asked By
Jude1qaz
0 points
N/A
Posted on - 09/15/2011
Hi,
I have written a java class to get all countries as follows. However, I need an optimized way of getting allcountries from a java library. Please suggest me a open source solution for this.
public class countries{
Â
public static String[] WorldCountry=new String[]{"Abkhazia","Afghanistan","Akrotiri and Dhekelia","Ã…land Islands","Albania","Algeria","American Samoa","Andorra","Angola","Anguilla",
"Antigua and Barbuda","Argentina ","Armenia ","Aruba","Ascension Island",………………….
Â
Thanks,
James
Is there a better API or library to get all countries
I do not know if there actually exist an API for the list of all countries but if you want to create it your own you can… instead of using a string, like you did above, i suggest that you use the enum types if you are using Java programming language. For example,
public enum Country {
FRANCE ("FRA"), GERMANY ("GER"), RUSSIA ("RUS"), USA("USA"),
CHINA ("CHN"), JAPAN("JPN"), PHILIPPINES ("PHI"), ...
}
To use the country of enum type,
Public class Test{
Country country;
public Test(Country country) {
this.country = country;
}
public static void main(String[] args) {
Test cname = new Test(country.PHILIPPINES);
System.out.println(cname);
}
}
OUTPUT : PHI
Â