Java Array Copy arraycopy(T[] src, int srcPos, T[] dest, int destPos, int length)

Here you can find the source of arraycopy(T[] src, int srcPos, T[] dest, int destPos, int length)

Description

Short-hand method for deciding whether or not to use the native System#arraycopy(Object,int,Object,int,int) method or an element-by-element copy, based on the #JNI_COPY_ARRAY_THRESHOLD .

License

Open Source License

Parameter

Parameter Description
src The source array.
srcPos The source starting position.
dest The destination array.
destPos The destination starting position.
length The amount of bytes to copy.

Declaration

private static <T> void arraycopy(T[] src, int srcPos, T[] dest, int destPos, int length) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*w w  w  . ja va2 s. c om*/
     * Empirically determined point at which the average cost of a JNI call exceeds the expense
     * of an element-by-element copy. This number may change over time.
     */
    private static final int JNI_COPY_ARRAY_THRESHOLD = 6;

    /**
     * Short-hand method for deciding whether or not to use the native
     * {@link System#arraycopy(Object, int, Object, int, int)} method or an element-by-element
     * copy, based on the {@link #JNI_COPY_ARRAY_THRESHOLD}.
     * 
     * @param src
     *            The source array.
     * @param srcPos
     *            The source starting position.
     * @param dest
     *            The destination array.
     * @param destPos
     *            The destination starting position.
     * @param length
     *            The amount of bytes to copy.
     */
    private static <T> void arraycopy(T[] src, int srcPos, T[] dest, int destPos, int length) {
        if (length >= JNI_COPY_ARRAY_THRESHOLD) {
            System.arraycopy(src, srcPos, dest, destPos, length);
        } else {
            for (int i = 0; i < length; i++) {
                dest[destPos + i] = src[srcPos + i];
            }
        }
    }
}

Related

  1. arraycopy(Object[] src, int srcPos, Object[] dest, int destPos, int length)
  2. arraycopy(String[] src)
  3. arrayCopy(String[][] src, int src_position, String[][] dst, int dst_position, int length)
  4. arraycopy(T[] a)
  5. arrayCopy(T[] objs)
  6. arraycopy(T[] src, int srcPos, T[] dst, int len)
  7. arrayCopy(T[] x)
  8. arrayCopyAndAddEntry(T[] base, T extra)
  9. arraycopyAndInsertInt(final int[] src, final int idx, final int value)