Here you can find the source of copyOf(T[] oriArray, int newArraySize, int startOffset)
Parameter | Description |
---|---|
T | a parameter |
oriArray | a parameter |
newArraySize | a parameter |
startOffset | a parameter |
@SuppressWarnings("unchecked") public static <T> T[] copyOf(T[] oriArray, int newArraySize, int startOffset)
//package com.java2s; //License from project: Open Source License public class Main { /**/* w w w . ja v a 2 s. co m*/ * Generates an copy of the array with some size modification. * TODOC * * @param <T> * @param oriArray * @param newArraySize * @param startOffset * @return */ @SuppressWarnings("unchecked") public static <T> T[] copyOf(T[] oriArray, int newArraySize, int startOffset) { // In Java 6 this would be a simple: Arrays.copyOf(msgArgs, argCount+1); // But the code should stay compatible to Java 5 for now. Object[] targetArray = new Object[newArraySize]; if (oriArray != null) { for (int i = startOffset, count = 0; i < newArraySize && count < oriArray.length; ++i, ++count) { targetArray[i] = oriArray[count]; } } return (T[]) targetArray; } public static <T> T[] copyOf(T[] oriArray, int newArraySize) { return copyOf(oriArray, newArraySize, 0); } }