|
| ||||||||||
| Tags: data structure, hashtable, java, linked list, programming language, sorting |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Problem sorting a Hashtable
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 ] |
|
#2
| |||
| |||
| 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
| |||
| |||
| 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
| |||
| |||
| 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 ] ] |
|
#5
| |||
| |||
| 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
| |||
| |||
| 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. |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Problem sorting a Hashtable" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| HashMap vs HashTable | Joyjeet | Software Development | 6 | 04-01-2011 08:07 PM |
| Hashtable vs Vector | Vodka | Software Development | 5 | 23-02-2010 01:43 AM |
| Manipulating a hashtable | Miles Runner | Software Development | 5 | 12-02-2010 12:20 AM |
| C# Hashtable vs list vs dictionary | Zaafir | Software Development | 3 | 31-07-2009 12:36 PM |
| How to use hashtable to replace content | RasMus | Software Development | 3 | 27-07-2009 10:30 AM |