-         /*
 
 -          * 编写程序,生成5个1至10之间的随机整数,存入一个List集合,
 
 -          * 编写方法对List集合进行排序(自定义排序算法,禁用Collections.sort方法和TreeSet), 然后遍历集合输出
 
 -          */
 
 -         public static void main(String[] args) {
 
 -                 // 创建集合对象
 
 -                 List<Integer> list = new LinkedList<>();
 
 -                 // 创建整数类型的数组,长度为5
 
 -                 int[] arr = new int[5];
 
 -                 // 创建数组的第一个索引
 
 -                 int index = 0;
 
 -                 // 当集合的长度为5时,退出循环
 
 -                 while (list.size() < 5) {
 
 -                         // 将生成的随机数添加到集合
 
 -                         list.add((int) (Math.random() * 10 + 1));
 
 -                 }
 
  
-                 // 通过集合对象获取迭代器对象
 
 -                 Iterator<Integer> it = list.iterator();
 
 -                 // 当获取的下一个元素返回为false时,退出循环
 
 -                 while (it.hasNext()) {
 
 -                         // 将遍历到的元素添加到数组
 
 -                         arr[index] = it.next();
 
 -                         // 每添加一次,数组索引自增一次
 
 -                         index++;
 
 -                         // System.out.println(it.next());
 
 -                 }
 
 -                 // 利用数组工具类对数组进行升序排序
 
 -                 Arrays.sort(arr);
 
 -                 // 将数组转换成字符串并打印输出
 
 -                 System.out.println(Arrays.toString(arr));
 
 -         }
 
  复制代码 |   
        
 
    
    
    
     
 
 |