发布网友 发布时间:2022-04-29 02:45
共2个回答
热心网友 时间:2022-06-29 00:26
实现是会变的,HashSet的迭代器在输出时“不保证有序”,但也不是“保证无序”。也就是说,输出时有序也是允许的,但是你的程序不应该依赖这一点。热心网友 时间:2022-06-29 00:26
This class implements the Set interface, backed by a hash table (actually a HashMap instance). 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. This class permits the null element.
看HashSet的API描述,说不保证循环元素的顺序,所以就有可能是有序的,也有可能是无序的。