not sure if I should search or sort my hashmap

后端 未结 6 1607
北恋
北恋 2021-01-23 16:28

Hi I have a list of people with their ages, I need to find those who are more than 30 years old, is there any possibility to search in a hashmap ? (please note that I may need

6条回答
  •  一生所求
    2021-01-23 16:58

    HashMap hmap = new HashMap();
    SortedSet keys = new TreeSet(hmap.keySet());
    

    This will give you a sorted set which you could make a subset of.

    keys.subSet(from,to) e.g keys.subSet(30,100)

    and you will have a set with all required elemets.

提交回复
热议问题