我想知道在 HashSet 中以何种方式检索数据 我以不同的顺序插入数据,输出数据的顺序不同。 有人可以告诉这背后的逻辑吗?
代码是这样的:-
class Test
{
public static void main(String[]args)
{
HashSet<String> h = new HashSet<String>();
// Adding elements into HashSet using add()
h.add("India");
h.add("Australia");
h.add("South Africa");
System.out.println(h);
}
}
输出:- [南非、澳大利亚、印度]
最佳答案
来自HashSet的Javadoc
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.
关于java - 在 HashSet 中检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52985177/