descendingMap(): This method is available in java.util.TreeMap class of Java.
Syntax:
NavigableMap<Integer, String> java.util.TreeMap.descendingMap()
This method returns a reverse order view of the mappings contained in this map.
Parameters: NA
Returns: a reverse order view of this map.
Exceptions: NA
Approach
Java
import java.util.TreeMap;public class TreeMapdescendingMap {public static void main(String[] args) {TreeMap<Integer, String> treeMap =new TreeMap<Integer, String>();treeMap.put(2, "Hello");treeMap.put(11, "Java");treeMap.put(23, "Program");treeMap.put(6, "C++");treeMap.put(25, "Program");System.out.println(treeMap.descendingMap());}}
Output:
{25=Program, 23=Program, 11=Java, 6=C++, 2=Hello}
No comments:
Post a Comment