直接调用:
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