小白求解,为什么我这个Set不能实现随机输出呢?
public static void main(String[] args) { Set<String> set=new HashSet(); String[] string=new String[]{"1","2","3"}; System.out.print("原数组为:"); for (String string2 : string) { System.out.print(string2); } for (String string2 : string) { set.add(string2); } System.out.println(); System.out.println("长度为:"+set.size()); System.err.print("Set遍历:"); for (String string2 : set) { System.out.print(string2+" "); } }
每次运行结果都是 321 ,不是应该每次都随机吗?