Results 1 to 6 of 6

Thread: Problem sorting a Hashtable

  1. #1
    Join Date
    Dec 2009
    Posts
    192

    Problem sorting a Hashtable

    Hello,
    My program Hashtable out the following:
    Code:
    Hashtable [ (Integer) iden,    (Vector) params [ (int) 0 : (String) type,
        (int) 1 : (Float) prop
      (int) 2 : (Integer) tot,
     (int) 3 : (Integer) pgm ]
    I would like this Hashtable to be sorted by value (Float) prop. However, a Hashtable does not sort, and even less about the value of its parameter. Basically I have a problem in sorting a hashtable. I tried with Collection of ArrayList, but I do nothing. How to achieve this?

  2. #2
    Join Date
    Nov 2009
    Posts
    330

    Re: Problem sorting a Hashtable

    Hello,
    The hashtable, like the hashmap, did not order and therefore can not be sorted. If you want a combination key / value with an order, we will have to know everything about the implementation of SortedMap. List on the actual order, but they are not key associations value, so I doubt you should be interested in this.

  3. #3
    Join Date
    Dec 2009
    Posts
    192

    Re: Problem sorting a Hashtable

    Hello,
    Thank you for the reply. SortedMap seems interesting for me. So I can use a TreeMap (which implements SortedMap). TreeMap has a method put (Object, Object). In my case, how to use this method? Should I put (proportion PID) and then retrieve other information from a PID? I therefore Integer key of my TreeMap. How then sort them? TreeMap does not seem to be a way to sort the elements. If you know about any other alternative for this, then let me know.

  4. #4
    Join Date
    Dec 2009
    Posts
    204

    Re: Problem sorting a Hashtable

    Hello,
    I had a similar problem the I tried the TreeMap sorting, it is done well. But my problem is more complex and am unable to implement it. My Hashtable is as following:
    Code:
    Hashtable [ (Integer) id, (Vector) param [ (int) 0 : (String) ty,
                                               (int) 1 : (Float) propt
                    			   (int) 2 : (Integer) total,
    					   (int) 3 : (Integer) pgm ]  ]
    Do you have any solution for this. If you find one then please help me and post it back so that I can start with the remaining of my program.

  5. #5
    Join Date
    Nov 2009
    Posts
    446

    Re: Problem sorting a Hashtable

    Hello,
    Just have a look at the following code, I do not know your exact needs, but still you can refer this.
    Code:
    Hashtable [ 1000V [ tp1,
                          0.1,
    		      4451,
                          145 ]      ,
                2000V [ tp2,
                          0.4,
                          4451,
    		      41 ]       ,
                3000V [ tp3,
                          0.4,
                          4541,
    		      51 ]       ,
                4000V [ Type4,
                          0.2,
                          524,
    		      10 ]       ]

  6. #6
    Join Date
    Nov 2009
    Posts
    356

    Re: Problem sorting a Hashtable

    Hello,
    As I said earlier, to sort a list, but you lose the association key value. Or you reverse your map (become the key value and vice versa), then it is possible to sort based on the vector. The question is: do you need either the association key that is the value that is sorted? Depends totally on your needs, that is what is the result you want from your code and what exactly are your expecting your program to do.

Similar Threads

  1. HashMap vs HashTable
    By Joyjeet in forum Software Development
    Replies: 6
    Last Post: 04-01-2011, 09:07 PM
  2. Editing subject of a Hashtable
    By Aaliya Seth in forum Software Development
    Replies: 5
    Last Post: 23-02-2010, 04:38 AM
  3. Hashtable vs Vector
    By Vodka in forum Software Development
    Replies: 5
    Last Post: 23-02-2010, 02:43 AM
  4. Manipulating a hashtable
    By Miles Runner in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 01:20 AM
  5. C# Hashtable vs list vs dictionary
    By Zaafir in forum Software Development
    Replies: 3
    Last Post: 31-07-2009, 12:36 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,580,115.76925 seconds with 17 queries