zoukankan      html  css  js  c++  java
  • java数组之system.arrayCopy

    public class ArrayDemo {
    
        
       /* public static void main(String[] args) {
            int[] a=new  int[4];
            
            int[] b=new int[5];
            
            Arrays.fill(a, 1);
            Arrays.fill(b, 2);
            
            System.arraycopy(a, 0, b,0, 2);
    //        
            System.out.println(Arrays.toString(b));
            
    //        System.out.println(5/3);//返回整数部分
        }*/
    output:

    [1, 1, 2, 2, 2]

     
    
    
    public static void main(String[] args) {

    int[] a={1,2,3,4,5};

    
    

     

    
    

    int[] b= {6,7,8,9,10};

    
    

     

    
    

    // int[] b=new int[5];

    
    

     

    
    

    // Arrays.fill(b, 6);

    
    

     

    
    

    System.arraycopy(a, 1, b,2, 2);

    
    

    //

    
    

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

    }

    output:

    [6, 7, 2, 3, 10]

     

    这个浅拷贝是重要基础点,因为arraylist的动态扩容就是基于这个属性

    第一个参数是:源对象

    第二个:从源数组中的什么位置开始复制的偏移量

    第三个:待复制到的目标对象

    第四个:从目标数组的什么位置开始复制偏移量

    第五个:复制的个数

    注意:基本类型数组与对象类型数组都可以复制但如果复制的是对象那么需要注意的是复制的对象是引用,而不是对象本身的拷贝

  • 相关阅读:
    notebook笔记
    from __future__ import absolute_import
    GUI
    version_info
    函数参数
    None
    exec、eval
    os
    IGeometry接口
    IGeometry接口
  • 原文地址:https://www.cnblogs.com/zhangfengshi/p/9210581.html
Copyright © 2011-2022 走看看