zoukankan      html  css  js  c++  java
  • java.util.Arrays.copyOf 和 copyOfRange方法

    java.util.Arrays.copyOf 和 copyOfRange方法

    Modifier and Type 方法 描述
    static boolean[] copyOf(boolean[] original, int newLength) 复制指定的数组,截断或填充 false (如有必要),因此副本具有指定的长度。
    static byte[] copyOf(byte[] original, int newLength) 复制指定的数组,使用零截断或填充(如有必要),以使副本具有指定的长度。
    static char[] copyOf(char[] original, int newLength) 复制指定的数组,截断或填充空字符(如有必要),以便复制具有指定的长度。
    static double[] copyOf(double[] original, int newLength) 复制指定的数组,使用零截断或填充(如有必要),以使副本具有指定的长度。
    static float[] copyOf(float[] original, int newLength) 复制指定的数组,使用零截断或填充(如有必要),以使副本具有指定的长度。
    static int[] copyOf(int[] original, int newLength) 复制指定的数组,使用零截断或填充(如有必要),以使副本具有指定的长度。
    static long[] copyOf(long[] original, int newLength) 复制指定的数组,使用零截断或填充(如有必要),以使副本具有指定的长度。
    static short[] copyOf(short[] original, int newLength) 复制指定的数组,使用零截断或填充(如有必要),以使副本具有指定的长度。
    static T[] copyOf(T[] original, int newLength) 复制指定的数组,用空值截断或填充(如有必要),以便复制具有指定的长度。
    static T[] copyOf(U[] original, int newLength, Class newType) 复制指定的数组,用空值截断或填充(如有必要),以便复制具有指定的长度。
    static boolean[] copyOfRange(boolean[] original, int from, int to) 将指定数组的指定范围复制到新数组中。
    static byte[] copyOfRange(byte[] original, int from, int to) 将指定数组的指定范围复制到新数组中。
    static char[] copyOfRange(char[] original, int from, int to) 将指定数组的指定范围复制到新数组中。
    static double[] copyOfRange(double[] original, int from, int to) 将指定数组的指定范围复制到新数组中。
    static float[] copyOfRange(float[] original, int from, int to) 将指定数组的指定范围复制到新数组中。
    static int[] copyOfRange(int[] original, int from, int to) 将指定数组的指定范围复制到新数组中。
    static long[] copyOfRange(long[] original, int from, int to) 将指定数组的指定范围复制到新数组中。
    static short[] copyOfRange(short[] original, int from, int to) 将指定数组的指定范围复制到新数组中。
    static T[] copyOfRange(T[] original, int from, int to) 将指定数组的指定范围复制到新数组中。
    static T[] copyOfRange(U[] original, int from, int to, Class newType) 将指定数组的指定范围复制到新数组中。

    copyOf(int[] original, int newLength)

    import java.util.Arrays;
    
    public class TestCopyOf {
        public static void main(String[] args) {
            test();
    
        }
        //测试  copyOf()方法
        public static void test(){
            int[] a = {1,2,3,5,10,8};
            int[] copy = Arrays.copyOf(a, 4);
            System.out.println("复制数组的前4位:"+Arrays.toString(copy));
        }
    }
    
    
    复制数组的前4位:[1, 2, 3, 5]
    

    copyOfRange(int[] original, int from, int to)

    import java.util.Arrays;
    
    public class TestCopyOfRange {
        public static void main(String[] args) {
            test();
    
        }
        //测试  copyOfRange()方法
        public static void test(){
            int[] a = {1,2,3,5,10,8};
            int[] copy = Arrays.copyOfRange(a, 2,5);
            System.out.println("复制数组的2到4位:"+Arrays.toString(copy));
        }
    }
    
    
    复制数组的2到4位:[3, 5, 10]
    
  • 相关阅读:
    Spring--IOC
    神奇的小东西
    视图层发起请求的方式
    jdbc “贾琏欲执事”
    线程的五种状态
    java的<<左移,>>右移,>>>无符号右移
    直接插入排序(单链表排序)
    单链表相关知识以及指针引用相关知识
    将一个数n分解为若干个从小到大排列的质数的积 ,求质数因子
    最小二乘法
  • 原文地址:https://www.cnblogs.com/sweetorangezzz/p/12918802.html
Copyright © 2011-2022 走看看