Java Array Copy arrayCopy(Object[] source, Object[] target, int size)

Here you can find the source of arrayCopy(Object[] source, Object[] target, int size)

Description

Copy the elements of the source array to the target array.

License

Open Source License

Parameter

Parameter Description
source the source array
target the target array
size the number of elements to copy

Declaration

public static void arrayCopy(Object[] source, Object[] target, int size) 

Method Source Code

//package com.java2s;
/*/*  ww w . j ava 2  s .  co  m*/
 * Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License,
 * Version 1.0, and under the Eclipse Public License, Version 1.0
 * (http://h2database.com/html/license.html).
 * Initial Developer: H2 Group
 */

public class Main {
    /**
     * The maximum number of elements to copy using a Java loop. This value was
     * found by running tests using the Sun JDK 1.4 and JDK 1.6 on Windows XP.
     * The biggest difference is for size smaller than 40 (more than 50% saving).
     */
    private static final int MAX_JAVA_LOOP_COPY = 50;

    /**
     * Copy the elements of the source array to the target array.
     * System.arraycopy is used for larger arrays, but for very small arrays it
     * is faster to use a regular loop.
     *
     * @param source the source array
     * @param target the target array
     * @param size the number of elements to copy
     */
    public static void arrayCopy(Object[] source, Object[] target, int size) {
        if (size > MAX_JAVA_LOOP_COPY) {
            System.arraycopy(source, 0, target, 0, size);
        } else {
            for (int i = 0; i < size; i++) {
                target[i] = source[i];
            }
        }
    }
}

Related

  1. arraycopy(long src[], int srcOffset, long dest[], int destOffset, int limit)
  2. arraycopy(long[] src, int srcPos, long[] dest, int destPos, int length)
  3. arraycopy(Object dest, Object src1, int length1, Object src2, int length2)
  4. arrayCopy(Object src, int srcPos, Object dest, int destPos, int length)
  5. arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
  6. arraycopy(Object[] src, int srcPos, Object[] dest, int destPos, int length)
  7. arraycopy(String[] src)
  8. arrayCopy(String[][] src, int src_position, String[][] dst, int dst_position, int length)
  9. arraycopy(T[] a)