手写代码 - java.util.Arrays 相关

对primitive[]数组进行排序

直接使用Arrays.sort()即可。不必自己去写排序算法了。

 

 

 

拷贝一个范围内的数组

Arrays.copyOfRange( array, startIndex, endIndex);

include startIndex...

exclude endIndex...

 

用相同默认值,初始化一个数组

参数除了int类型,还能是多种primitive类型

    /**
     * Assigns the specified int value to each element of the specified array
     * of ints.
     *
     * @param a the array to be filled
     * @param val the value to be stored in all elements of the array
     */
    public static void fill(int[] a, int val) {
        for (int i = 0, len = a.length; i < len; i++)
            a[i] = val;
    }

 

posted on 2019-03-19 22:49  frank_cui  阅读(137)  评论(0编辑  收藏  举报

导航

levels of contents