I have a map declared as follows –
Map<Date, Long[]> myMap = new TreeMap<Date, Long[]>();
I put some key-value pairs in that map, check the size as follows –
myMap.size(); //returns 29
myMap.values().size(); //returns 31
All the dates (keys) are distinct.
Aren’t those two supposed to return same values?
Given that the collection returned by TreeMap’s values() method (in JDK 6, at least) has a size as follows:
I’d say you have something adding new entries to the map between your two
size()calls. To be clear,map.values().size()delegates tomap.size(). Therefore there’s no way they can return two different values for the same map with the same contents.