Here you can find the source of arrayCopy(Object[] source, Object[] target, int size)
Parameter | Description |
---|---|
source | the source array |
target | the target array |
size | the number of elements to copy |
public static void arrayCopy(Object[] source, Object[] target, int size)
//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]; } } } }