rtz

HashSet order and difference with JDK 7 / 8

匿名 (未验证) 提交于 2019-12-03 00:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This is a two part question: Does HashSet implement some hidden ordering mechanic or it just, to quote the documentation: 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. tells me that the order MIGHT change sometimes in the future and/or depending on memory usage? Why am I getting completely different 'ordering' (dare I say) when I switch between JDKs? Take this example: for (int i = 0; i < 1000; i++) { Set<String> stringSet = new HashSet<>();