Arrays 的用法

直接调用:
 1 import java.util.Arrays;
 2 
 3 public class Array03 {
 4     public static void main(String[] args) {
 5         int[] a = {5,6,3,4,2,5,21,56,5,5,2,1};
 6         System.out.println(Arrays.toString(a));//输出数组
 7 
 8         Arrays.sort(a);//数组升序排序
 9         System.out.println(Arrays.toString(a));
10 
11         Arrays.fill(a,2,4,0);//数组指定位置填充
12         System.out.println(Arrays.toString(a));
13     }
14 
15 }结果
结果:
[5, 6, 3, 4, 2, 5, 21, 56, 5, 5, 2, 1]
[1, 2, 2, 3, 4, 5, 5, 5, 5, 6, 21, 56]
[1, 2, 0, 0, 4, 5, 5, 5, 5, 6, 21, 56]

Process finished with exit code 0

 

 
上一篇:【LeetCode】137. 只出现一次的数字 II(剑指offer 56-II)


下一篇:接口测试平台代码实现56:首页重构-4