public class ArrayDemo06 {public static void main(String[] args) {int[] a = {1,4,2,6,5,8,7};System.out.println(a); //hashCode [I@1b6d3586// 打印数组元素 Arrays.toStringSystem.out.println(Arrays.toString(a)); // [1, 4, 2, 6, 5, 8, 7]// 自己写一个方法去打印printArray(a);System.out.println("\n*********");Arrays.sort(a); // 数组进行排序: 升序System.out.println(Arrays.toString(a));Arrays.fill(a, 1); // 数组填充Arrays.fill(a, 2, 4, 3); // 2到4之间填充3System.out.println(Arrays.toString(a)); // [1, 1, 3, 3, 1, 1, 1]}public static void printArray(int[] a){for (int i = 0; i < a.length; i++) {if (i==0){System.out.print("[");}if (i==a.length-1){System.out.print(a[i]+"]");} else {System.out.print(a[i]+", ");}}}
}
https://www.bilibili.com/video/BV12J41137hu?p=57&spm_id_from=pageDriver