五、Arrays类常用方法

public class Demo03 {

    public static void main(String[] args) {

        int[] nums = {5,2,86,12,45,756,12,3,1,9,32,7856};

        System.out.println(Arrays.toString(nums));

        //排序
        Arrays.sort(nums);

        System.out.println(Arrays.toString(nums));

        //二分查找 PS:调用此方法前必须排序,因为二分查找是基于顺序表。
        int result = Arrays.binarySearch(nums, 32);
        System.out.println(result);

        //打印输出
        Arrays.toString(nums);

        //填充
        Arrays.fill(nums,0);

        //复制
        int[] nums2 = Arrays.copyOf(nums, 10);
    }
}

 

posted @ 2022-05-12 02:28  Epiphany8Z  阅读(28)  评论(0编辑  收藏  举报