Here you can find the source of arrayCopy(T[] objs)
Parameter | Description |
---|---|
T | the generic type of the array. |
objs | the array. |
null
if the array is null.
public static <T> T[] arrayCopy(T[] objs)
//package com.java2s; /** Various utility functions for Java. * <p>/*from w ww . ja v a2 s .c o m*/ * Copyright (c) 2008 Eric Eaton * <p> * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * <p> * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * <p> * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. * * @author Eric Eaton (EricEaton@umbc.edu) <br> * University of Maryland Baltimore County * * @version 0.1 * */ public class Main { /** Copy the given array. * @param <T> the generic type of the array. * @param objs the array. * @return a copy of the array, <code>null</code> if the array is null. */ public static <T> T[] arrayCopy(T[] objs) { if (objs == null) return null; Object[] copy = new Object[objs.length]; System.arraycopy(objs, 0, copy, 0, objs.length); return (T[]) copy; } /** Copy the given array. * @param objs the array. * @return a copy of the array, <code>null</code> if the array is null. */ public static int[] arrayCopy(int[] objs) { if (objs == null) return null; int[] copy = new int[objs.length]; System.arraycopy(objs, 0, copy, 0, objs.length); return copy; } /** Copy the given array. * @param objs the array. * @return a copy of the array, <code>null</code> if the array is null. */ public static double[] arrayCopy(double[] objs) { if (objs == null) return null; double[] copy = new double[objs.length]; System.arraycopy(objs, 0, copy, 0, objs.length); return copy; } }