I have a List of object as List<Human> humanList;
which human object consist of 5 variable as firstname, lastname,color,length,sex.
How can i check out to see the variable(firstname) how many times appear/exist in the list?
List<Human> humanList = getHumanList();
for(Human human :humanList){
}
Assuming here
firstnameis of typeString, if it is not – change it as needed.Create a
Map<String,Integer>(let it bemap) which will be used as a histogram.Iterate the list, and for each human:
When you are done
mapholds eachfirstNameas a key and the number of its occurances as the matching value.