Я думаю, что вы можете использовать enum для своей проблемы. Определите все известные названия стран и отрасли в перечислении, подобном этому.
public enum Country {
au,
be;
int Int=this.ordinal();//just a short name for ordinal
}
и
public enum Industry {
foo,
bar,
baz;
int Int=this.ordinal();
}
Теперь определите массив 2d int, и вы можете установить значения с помощью перечисления следующим образом:
int[][] value=new int[Country.values().length][Industry.values().length];
value[Country.au.Int][Industry.bar.Int]=2;
//Read from JSON
value[Country.valueOf("au").Int][Industry.valueOf("bar").Int]=2;
Вы можете добавить этот код в конец вашего текущего цикла for, если вы используете enum:
value[Country.valueOf(country).Int][Industry.valueOf(industry).Int]=count;
Другой вариант - избежать массива и использовать вместо него Map:
Map<Country,Map<Industry,Integer>> m=new HashMap<Country,Map<Industry,Integer>>();
или просто без перечислений:
Map<String,Map<String,Integer>> m=new HashMap<String,Map<String,Integer>>();
Проблема с картой заключается в том, что добавлять и извлекать значения из нее немного сложно, но вы можете написать общий метод для выполнения этой работы.
UPDATE:
Добавление значений на внутреннюю карту:
String[][] countryAndIndustry= {{"au","foo"},{"au","bar"},{"be","baz"}};
Integer[] count= {2,1,2};
HashMap<String,HashMap<String,Integer>> hm=new HashMap<String, HashMap<String,Integer>>();
for(int i=0;i<count.length;i++)
{
HashMap<String,Integer> innerMap=hm.get(countryAndIndustry[i][0]);
if(innerMap==null)
{
innerMap=new HashMap<String, Integer>();
hm.put(countryAndIndustry[i][0],innerMap);
}
innerMap.put(countryAndIndustry[i][1],count[i]);
}