Java Array Copy arrayCopyToNull(T[] source, int sourceOffset, T[] destination, int destinationOffset)

Here you can find the source of arrayCopyToNull(T[] source, int sourceOffset, T[] destination, int destinationOffset)

Description

Copies references from one array to another until it hits a null sentinel reference or the end of the source array.

License

Open Source License

Parameter

Parameter Description
T the object type stored in the arrays.
source the source array.
sourceOffset the source offset.
destination the destination array.
destinationOffset the starting destination offset.

Exception

Parameter Description
ArrayIndexOutOfBoundsException if this tries to resolve a destination that is out of bounds.

Return

how many references were copied.

Declaration

public static <T> int arrayCopyToNull(T[] source, int sourceOffset, T[] destination, int destinationOffset) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009-2016 Black Rook Software
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
 ******************************************************************************/

public class Main {
    /**//from   www.  ja va 2s .  c om
     * Copies references from one array to another until 
     * it hits a null sentinel reference or the end of the source array.
     * @param <T> the object type stored in the arrays.
     * @param source the source array.
     * @param sourceOffset the source offset.
     * @param destination the destination array.
     * @param destinationOffset the starting destination offset.
     * @return how many references were copied.
     * @throws ArrayIndexOutOfBoundsException if this tries to resolve a destination that is out of bounds.
     * @since 2.21.0
     */
    public static <T> int arrayCopyToNull(T[] source, int sourceOffset, T[] destination, int destinationOffset) {
        int s;
        for (s = 0; s + sourceOffset < source.length && source[s + sourceOffset] != null; s++)
            destination[s + destinationOffset] = source[s + sourceOffset];
        return s;
    }
}

Related

  1. arraycopy(T[] src, int srcPos, T[] dest, int destPos, int length)
  2. arraycopy(T[] src, int srcPos, T[] dst, int len)
  3. arrayCopy(T[] x)
  4. arrayCopyAndAddEntry(T[] base, T extra)
  5. arraycopyAndInsertInt(final int[] src, final int idx, final int value)
  6. arrayCopyWithRemoval(Object[] src, Object[] dst, int idxToRemove)
  7. Arrays_copyOf(int[] pos, int length)
  8. copy(byte[] bytes)
  9. copy(byte[] data, int from)