How do I get the second maximum value from a Hashtable which contains integer value. say Hashtable Hsm = new Hashtable(); Hsm.put("1", 2); Hsm.put("2", 3); Hsm.put("3", 4); Hsm.put("4", 5); Hsm.put("5", 6); Hsm.put("6", 7); Hsm.put("7", 8); Hsm.put("8", 9); Hsm.put("9", 11); Hsm.put("10", 10);
I want to fetch the second highest value.pls help me.
Afternoon. Please don't use Hashtable; declare it as a Map and then use HashMap. Hashtable is generally regarded as a legacy class.
You aren't putting Integers into anything, but ints, so you are going to have to set the Map up with generic typing. There are methods in the Map interface which allow you to get a Collection of all the values. Once you have got that, go through the Collection interface and the Collections class and see whether you can get them into any semblance of order.
Have you made any effort to find the answer on your own? Have you looked at the API documentation for Hashtable to see what it can do? Have you looked at the rest of the Collections API to see what facilities are built-in to Java?