有时候为了预览集合值,多次循环很麻烦,可以使用将集合转数组,利用arrays的方法直接打印出值
   
@Test
public void xiao_hong_shu(){
     //生成一个arraylist,然后添加数组进去
     List<int[]> list = new ArrayList();
     Random r = new Random();
     for(int i=-0;i<=10;i++){
         list.add(new int[]{r.nextInt(3),r.nextInt(11),r.nextInt(11)});
     }
     //将集合转数组,然后转string
     System.out.println(Arrays.deepToString(list.toArray()));
 }
    
    
    输出:
   
[[1, 1, 9], [0, 7, 10], [0, 2, 10], [0, 3, 1], [1, 6, 1], [2, 8, 1], [0, 5, 7], [1, 5, 7], [2, 9, 2], [0, 2, 10], [1, 9, 2]]
- 
     
 r.nextInt(3)
 
 – 生成0-2的随机整数
- 
     
 Arrays.toString()
 
 – 可以打印出单层数组
- 
     
 Arrays.deepToString()
 
 – 打印出数组嵌套数组
- 
     
 Arrays.sort()
 
 – 排序
 
版权声明:本文为wayhb原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
