You can try HashMap . Using HashMap, you can use the country code as a key, and the number of times how many times each is displayed as the value stored in this key. If this is your first time encountering a specific country code, insert it into the map with an initial value of 1; otherwise increase the existing value.
HashMap<String, Integer> myMap = new HashMap<String, Integer>();
for (... record : records) {
String countryCode = record.getCountryCode();
int curVal;
if (myMap.containsKey(countryCode)) {
curVal = myMap.get(countryCode);
myMap.put(countryCode, curVal + 1);
} else {
myMap.put(countryCode, 1);
}
}
source
share