Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 04-02-2010
Member
 
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?
Reply With Quote
  #2  
Old 04-02-2010
Member
 
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.
Reply With Quote
  #3  
Old 04-02-2010
Member
 
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.
Reply With Quote
  #4  
Old 04-02-2010
Member
 
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.
Reply With Quote
  #5  
Old 04-02-2010
Member
 
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 ]       ]
Reply With Quote
  #6  
Old 04-02-2010
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Problem sorting a Hashtable"
Thread Thread Starter Forum Replies Last Post
HashMap vs HashTable Joyjeet Software Development 6 04-01-2011 09:07 PM
Editing subject of a Hashtable Aaliya Seth Software Development 5 23-02-2010 04:38 AM
Hashtable vs Vector Vodka Software Development 5 23-02-2010 02:43 AM
Manipulating a hashtable Miles Runner Software Development 5 12-02-2010 01:20 AM
C# Hashtable vs list vs dictionary Zaafir Software Development 3 31-07-2009 12:36 PM


All times are GMT +5.5. The time now is 03:23 AM.