1.copy

public class Copy {
    public static void main(String[] args) {
        int[] a = {3,5,6,87,98,9};
        System.out.println("------手工复制-------");
        int[] b = new int[a.length];
        
        for (int i=0;i<a.length;i++) {
            b[i] = a[i];
        }
        
        System.out.println("-----Arrays.copyOf复制----");
        //1参数:源数组,2参数:复制的长度,从0位置开始复制
        int[] c = Arrays.copyOf(a, 4);
        for (int i : c) {
            System.out.println(i);
        }
        System.out.println("---System.arrayCopy-------");
        int[] d = new int[10];
        //源数组,源数组开始复制的索引位置,目标数组,目标数组的开始插入索引位置,要复制的长度
        System.arraycopy(a,1, d, 3, 3);
        for (int i : d) {
            System.out.println(i);
        }
        
        
    }

}
View Code

相关文章:

  • 2021-05-26
  • 2022-12-23
  • 2021-12-14
  • 2022-01-24
  • 2021-06-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-26
  • 2021-06-21
  • 2022-01-12
相关资源
相似解决方案