Why doesn't java.util.HashSet have a get(Object o) method?

后端 未结 11 2207
暖寄归人
暖寄归人 2020-12-07 18:39

I\'ve seen other questions about getting objects from Set\'s based on index value and I understand why that is not possible. But I haven\'t been able to find a

11条回答
  •  执念已碎
    2020-12-07 19:10

    Java Map/Collection Cheat Sheet

    Will it contain key/value pair or values only?

    1) If it contains pairs, the choice is a map. Is order important?

    . 1-1) If yes, follow insertion order or sort by keys?

    . . 1-1-1) If ordered, LinkedHashMap

    . . 1-1-2) If sorted, TreeMap

    . 1-2) If order is not important, HashMap

    2) If it stores only values, the choice is a collection. Will it contain duplicates?

    . 2-1) If yes, ArrayList

    . 2-2) If it will not contain duplicates, is primary task searching for elements (contains/remove)?

    . . 2-2-1) If no, ArrayList

    . . 2-2-2) If yes, is order important?

    . . . 2-2-2-1) If order is not important, HashSet

    . . . 2-2-2-2) If yes, follow insertion order or sort by values?

    . . . . 2-2-2-2-1) if ordered, LinkedHashSet

    . . . . 2-2-2-2-2) if sorted, TreeSet

提交回复
热议问题