Results 1 to 3 of 3

Thread: Sorting a hash map based on its keys

  1. #1
    Junior Member
    Join Date
    Aug 2007
    Answers
    18

    Sorting a hash map based on its keys

    hi, can anyone tell me how to sort records in a hashmap based on its keys?


  2. #2
    Junior Member
    Join Date
    Oct 2007
    Answers
    5

    Re: Sorting a hash map based on its keys

    TreeMap map = new TreeMap(hashMap) takes care or ordering process


  3. #3
    Expert Member
    Join Date
    Mar 2012
    Answers
    208

    Re: Sorting a hash map based on its keys

    Sorting can be done by placing the hash map on to o tree map (TreeMap is sorted by nature)

    Map myMap = new HashMap();
    // put keys and values........
    Map sortedMap = new TreeMap(myMap);


  4.  Sponsored Ads
    Ad


     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact