Does the entrySet() function that is called from a treemap instance return a TreeSet of entry’s or simply a set of entry’s.Is the order ensured?
Instead of getting it as a set of entry’s how can a get a list of entry’s in order?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s the other way around: a TreeSet uses a TreeMap internally. (See first sentence of the TreeSet docs)
There’s not much Sun java source code I can find on the web to link to, but here are some oldish versions:
As you can see, TreeMap defines an inner class called TreeMap.EntrySet which just extends AbstractSet. And no, it does not implement SortedSet (which would otherwise probably be specified by the SortedMap.entrySet() contract).
But to answer the actual question: yes, the order is ensured as specified in the SortedMap.entrySet() contract.
Update: JavaDoc links updated for Java 8, sources are still Java 6