I understand your question as follows:
You want to store associations of country to collection-of-{sate, data1, data2}, and later access the collection that is associated with a specific country.
In this case you can use a HashMap
, which provides just such association. Assuming you have a StateData
class that captures the {state, data1, data2} triple, you can write:
HashMap<String, Collection<StateData>> countries;
Populate the map with:
List<StateData> stateColl = new LinkedList<StateData>();
Map<String, List<StateData>> countries = new HashMap<String, List<StateData>>();
countries.put("USA", stateColl);
stateColl.add(stateData1);
stateColl.add(stateData2);
//...
where stateData1
,... is of type StateData
. Note that you can use any collection that fits your needs instead of LinkedList
. You could also use a TreeMap
instead of the HashMap
if you need to store the countries in (alphabetical) order, but that comes with some performance hits.
Then access the state collections as:
List<StateData> stateColl = countries.get("USA");
for (StateData stateData : stateColl)
{
// process the state info
}