What does the map size () method return?

I have a card declared as follows -

Map<Date, Long[]> myMap = new TreeMap<Date, Long[]>(); 

I put a few key-value pairs in this card, check the size as follows -

 myMap.size(); //returns 29 myMap.values().size(); //returns 31 

All dates (keys) are different.

Shouldn't these two return the same value?

+7
source share
1 answer

Given that the collection returned by the TreeMap () value method (at least in JDK 6) has the following size:

 public int size() { return TreeMap.this.size(); } 

I would say that you have something adding new entries to the map between two calls to size() . To be clear, map.values().size() delegates to map.size() . Therefore, there is no way to return two different values ​​for the same card with the same content.

+11
source

All Articles