BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 08-30-2007, 04:12 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Jul 2007
Model: 8800
PIN: N/A
Carrier: TDC
Posts: 115
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default sorting a list of strings

Please Login to Remove!

Man im pulling my hair here.... Problem is pretty simple however i cant get it to work...

im having a list of strings that i retreive through a hashmap... now i want to sort that list.
what to do from here...
Quote:
Hashtable hashtable=new hashtable with some value in it
SimpleSortingVector sortedVector=new SimpleSortingVector();
for (Enumeration e=hashtable.keys(); e.hasMoreElements();) {
sortedVector.add=(String)hashtable.get(e.nextEleme nt());
}
im really not familier with the comparable interface... can someone help me with an example plz?
Offline  
Old 08-30-2007, 04:44 AM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: Jul 2007
Model: 8800
PIN: N/A
Carrier: TDC
Posts: 115
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I figured it out....



I made this class (the comparator)
Quote:
/**
package source ;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.util.*;
import java.util.*;
*/
class ComparatorObjekt implements Comparator {
private String value;
/*ComparatorObjekt(String value) {
this.value = value; }
*/

public int compare (Object key1,Object key2)
{

return ((((String) key1).compareTo((String) key2)));
}

}
then i simply used

Quote:

sortedVector.setSortComparator(new ComparatorObjekt());
sortedVector.reSort();

case closed
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

35-PCS FREQUENCY CRYSTAL 7.3728MHZ 20PF 4-PIN SMD FOX FPX073-20 FPX073-20 07320
$24.98
35-PCS FREQUENCY CRYSTAL 7.3728MHZ 20PF 4-PIN SMD FOX FPX073-20  FPX073-20 07320 picture80-PCS CRYSTAL FREQUENCY ECS INC ECS-040-20-5P-TR 040205 ECS040205PTR
$25.35
80-PCS CRYSTAL FREQUENCY ECS INC ECS-040-20-5P-TR 040205 ECS040205PTR picture25-PCS CRYSTAL FREQUENCY EPSON SG-615PH32000MC0 615PH32000MC0 SG615PH32000MC0
$28.32
25-PCS CRYSTAL FREQUENCY EPSON SG-615PH32000MC0 615PH32000MC0 SG615PH32000MC0 picture40-PCS CRYSTAL FREQUENCY KDS SMD-49-20.000MHZ 4920000 SMD4920000MHZ
$27.02
40-PCS CRYSTAL FREQUENCY KDS SMD-49-20.000MHZ 4920000 SMD4920000MHZ picture55-PCS CRYSTAL FREQUENCY ABRACON ABLS-24.576MHZ-F-T 24576 ABLS24576MHZFT
$24.93
55-PCS CRYSTAL FREQUENCY ABRACON ABLS-24.576MHZ-F-T 24576 ABLS24576MHZFT picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.