Why the order of elements in HashSet's keySet changes from run to run?

后端 未结 3 1073
抹茶落季
抹茶落季 2021-01-13 04:42

I have some code utilizing standard Java collections: arrays, ArrayDeques, HashMaps, Lists, HashSets. My code is expected to be deterministic: the hash codes of all the elem

3条回答
  •  误落风尘
    2021-01-13 05:18

    From the documentation of HashSet:

    It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time.

提交回复
热议问题