I have a List of Pin objects (List<Pin>) where the Pin class has the following attributes:
String pinNumber, String pinType, Date insertDate
I would like to get a HashMap with <String pinNumber, int count> that have the distinct pinNumber telling me how many distinct pinNumber are in the List<Pin> and a count of each.
So the way I know of to do this is to:
- Iterate through the
List<Pin> - Check if the
HashMapcontains already the key value of the pinNumber and: - Increase it or add it if it does not exist.
I would like to do the same for each of the fields from the Pin object.
I am sure there should be an easier way to do this?
Maybe Guava has something simpler?
Even Simpler implementation: