File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes HashTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HashTable" Watch "HashTable" New topic
Author

HashTable

AmitV VermaV
Greenhorn

Joined: Dec 08, 2006
Posts: 2
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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38016
    
  22
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.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

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?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38016
    
  22
You may have to get your results into a List; then see if you can sort a List
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HashTable
 
Similar Threads
struct in java
Random Numbers II
Comparing Array Elements
Sudoku puzzle
Prime numbers