GeekInterview.com
Results 1 to 3 of 3

Sorting a hash map based on its keys

This is a discussion on Sorting a hash map based on its keys within the Java forums, part of the Software Development category; hi, can anyone tell me how to sort records in a hashmap based on its keys?...

  1. #1
    3roses is offline Junior Member Array
    Join Date
    Aug 2007
    Answers
    22

    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
    darth_lucifer is offline Junior Member Array
    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
    Sandhya.Kishan is offline Expert Member Array
    Join Date
    Mar 2012
    Answers
    212

    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);


    •    Sponsored Ads