Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

    Default 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;
    }


  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

    Default

    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...

  4. #4
    javastuden's Avatar
    javastuden is offline Senior Member
    Join Date
    Nov 2009
    Posts
    162
    Rep Power
    5

  5. #5
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

    Default

    i had try it...but still not solve my problem...

  6. #6
    javastuden's Avatar
    javastuden is offline Senior Member
    Join Date
    Nov 2009
    Posts
    162
    Rep Power
    5

    Default

    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

  7. #7
    Join Date
    Feb 2010
    Posts
    7
    Rep Power
    0

    Default

    tq for reply,

    it solved my problem..i just change from hashmap to sortmap...it working very well...

Similar Threads

  1. Hash
    By sandy1028 in forum New To Java
    Replies: 4
    Last Post: 04-17-2009, 10:36 AM
  2. Hash Map
    By rekha in forum New To Java
    Replies: 1
    Last Post: 03-21-2009, 01:00 PM
  3. Using Merge Sort to sort an ArrayList of Strings
    By coldfire in forum New To Java
    Replies: 3
    Last Post: 03-13-2009, 01:03 AM
  4. Hash Values ???
    By MuslimCoder in forum New To Java
    Replies: 6
    Last Post: 01-16-2009, 04:26 AM
  5. How to sort a list using Bubble sort algorithm
    By Java Tip in forum Algorithms
    Replies: 3
    Last Post: 04-29-2008, 08:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •