1.首先是这样分析的:利用hashset的特性这个容器中保存的内容是按着集合的规则的排序的。 2.获取一个不可重复的容器 3.为容器添加900个不同的元素 4.再遍历容器 public static void main(String[] args) { Set<Integer> set = new HashSet<Integer>(); while(set.size()<900){ int num = (int) (Math.random()*1000); set.add(num); } for (Integer it: set) { System.out.print(it+" "); } System.out.println("***************"+set.size()+"**********"); }