This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
TreeMap is a sorted map.But, haw can I know that it is sorted map and I want to know the keys in the map are sorted or values are sorted ,then how can I iterate the TreeMap so that I know that it is sorted. [ September 25, 2008: Message edited by: Ashok Pradhan ]
Hi Ashok, Maps don't come with iterators. You will have to convert a Map to a Set in order to iterate through it. Map API has a method called entrySet() that returns a Set of Map.Entry elements. Entry is a static inner class of the Map interface that holds the key/value pair. You can use the getKey() and getValue() methods of the Map.Entry class to retrieve the key/value. You can look at the Map.Entry API for further details. Here's some sample code:
[ September 25, 2008: Message edited by: Seema Gaurav ]
[ September 25, 2008: Message edited by: Seema Gaurav ] [ September 25, 2008: Message edited by: Seema Gaurav ]