Results 1 to 7 of 7
Thread: how to sort in this hash map
- 03-11-2010, 03:47 AM #1
Member
- Join Date
- Feb 2010
- Posts
- 7
- Rep Power
- 0
how to sort in this hash map
i need to sort this in drop down list...please help me...
this is the coding to call data from my database and it will appear in drop down list in my application..how to sort it in ascending order
public Map<String, String> getSalmoOptions() {
/*
if (logger.isDebugEnabled()) {
logger.debug("getKavOptions()");
}*/
Map<String, String> salmoOptions = null;
List<Salmonella> salmonellas = null;
if(salmoOptions == null){
salmoOptions = new HashMap<String, String>();
salmonellas = salmonellaManager.getAll();
if(salmonellas != null && !salmonellas.isEmpty()){
for(Salmonella salmonella : salmonellas){
salmoOptions.put(salmonella.getName(), salmonella.getId().toString());
}
}
}
return salmoOptions;
}
-
Are you sure that you want to use a HashMap if you want it sorted?
- 03-11-2010, 04:06 AM #3
Member
- Join Date
- Feb 2010
- Posts
- 7
- Rep Power
- 0
thank for reply...
yes....i just be pointed in this project..all list is using this hashmap for this project...if i want to change it, it will take times...hopefully i could use this hashmap...
or any other suggestion..actually i am new in java so i am not really sure...
tanks in advance...
- 03-11-2010, 04:22 AM #4
- 03-11-2010, 04:31 AM #5
Member
- Join Date
- Feb 2010
- Posts
- 7
- Rep Power
- 0
i had try it...but still not solve my problem...
- 03-11-2010, 05:18 AM #6
go through this
import java.util.*;
public class English {
public static void main (String[] args) {
SortedMap ma=new TreeMap();
char letter;
for (letter = 'z'; letter>='a'; letter--) {
ma.put(letter,letter);
}
Iterator iterator = ma.keySet().iterator();
while (iterator.hasNext()) {
Object key = iterator.next();
System.out.println("key : " + key + " value :" + ma.get(key));
}
}
}
if got idea and got as per your need just put the corredted code please
thank you
- 03-17-2010, 02:19 AM #7
Member
- Join Date
- Feb 2010
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
Hash
By sandy1028 in forum New To JavaReplies: 4Last Post: 04-17-2009, 10:36 AM -
Hash Map
By rekha in forum New To JavaReplies: 1Last Post: 03-21-2009, 01:00 PM -
Using Merge Sort to sort an ArrayList of Strings
By coldfire in forum New To JavaReplies: 3Last Post: 03-13-2009, 01:03 AM -
Hash Values ???
By MuslimCoder in forum New To JavaReplies: 6Last Post: 01-16-2009, 04:26 AM -
How to sort a list using Bubble sort algorithm
By Java Tip in forum AlgorithmsReplies: 3Last Post: 04-29-2008, 08:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks