I want to have a List
or Array
of some sort, storing this information about each country:
Just make an enum called Country. Java enums can have properties, so there's your country code and name. For the continent, you pobably want another enum.
public enum Continent
{
AFRICA, ANTARCTICA, ASIA, AUSTRALIA, EUROPE, NORTH_AMERICA, SOUTH_AMERICA
}
public enum Country
{
ALBANIA("AL", "Albania", Continent.EUROPE),
ANDORRA("AN", "Andorra", Continent.EUROPE),
...
private String code;
private String name;
private Continent continent;
// get methods go here
private Country(String code, String name, Continent continent)
{
this.code = code;
this.name = name;
this.continent = continent;
}
}
As for storing and access, one Map for each of the fields you'll be searching for, keyed on that that field, would be the standard solution. Since you have multiple values for the continent, you'll either have to use a Map, List
, or a Multimap implementation e.g. from Apache commons.