编程语言
首页 > 编程语言> > Java 数组复制

Java 数组复制

作者:互联网

目录


数组复制

import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        int[] src = {1, 2, 3, 4, 5, 6, 7};
        int[] dest = new int[3];
        //arraycopy(Object src, int srcIndex, Object dest, int destIndex, int length);
        //srcIndex, destIndex都表示从哪个下标开始复制
        System.arraycopy(src,2,dest,0,3);
        System.out.println(Arrays.toString(dest));
    }
}
/*
输出
[3, 4, 5]
 */

1. System.java

    @HotSpotIntrinsicCandidate
    public static native void arraycopy(Object src,  int  srcPos,
                                        Object dest, int destPos,
                                        int length);

    /**
     * Returns the same hash code for the given object as
     * would be returned by the default method hashCode(),
     * whether or not the given object's class overrides
     * hashCode().
     * The hash code for the null reference is zero.
     *
     * @param x object for which the hashCode is to be calculated
     * @return  the hashCode
     * @since   1.1
     * @see Object#hashCode
     * @see java.util.Objects#hashCode(Object)
     */

2. API

标签:src,Java,dest,srcPos,int,length,复制,数组,array
来源: https://blog.csdn.net/Regino/article/details/104699311