I'm trying to iterate through a hashmap and print out the ArrayList that is affiliated with each key. I have a hashmap that takes in a object and an arraylist. The object is the key. The way I'm currently doing it, it seems to be printing out a big list, but the map size is only 3.. What am I doing wrong? There should only be an ArrayList per each key.. And in my Class, I have an equals function and hashcode function to check for duplicate key. If it exists I just add to the arraylist. If it doesn't I add the new key, and a new arraylist.
Well, first things first - please make sure that in reality there are only 3 keys in the Map. You can easily figure this out during debugging (or by 'size' method of HashMap).
Secondly, if you are putting more than 3 keys and because some are duplicate, you are thinking that there should be actually 3 unique keys, then have a close look at hashCode and equals methods of ConflictId class. Make sure that those methods do follow the proper contract(s).
Yea I did the size method on Map that's how I was able to determine the actual size.
I did look at the methods inside the ConflictId and did a printout to make sure it's being called and it is.
I just don't understand why I'm getting a bunch more output... If you can think of anything else let me know.. Thank you.
Joined: Feb 19, 2012
I actually figured it out this morning at my desk what I was doing wrong. Inside another function where I call my iteration function I was calling inside a loop where I had thought it was outside... So that was the reason for the multiple output.