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:
public int size() {
return TreeMap.this.size();
}
I'd say you have something adding new entries to the map between your two size()
calls. To be clear, map.values().size()
delegates to map.size()
. Therefore there's no way they can return two different values for the same map with the same contents.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With