Java tutorial
//package com.java2s; /* * Copyright (C) 2014-present, Wei Chou (weichou2010@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { public static long[] copy(long[] array) { if (array == null) return new long[0]; long[] newArray = new long[array.length]; System.arraycopy(array, 0, newArray, 0, array.length); return newArray; } public static int[] copy(int[] array) { if (array == null) return new int[0]; int[] newArray = new int[array.length]; System.arraycopy(array, 0, newArray, 0, array.length); return newArray; } public static short[] copy(short[] array) { if (array == null) return new short[0]; short[] newArray = new short[array.length]; System.arraycopy(array, 0, newArray, 0, array.length); return newArray; } public static byte[] copy(byte[] array) { if (array == null) return new byte[0]; byte[] newArray = new byte[array.length]; System.arraycopy(array, 0, newArray, 0, array.length); return newArray; } public static double[] copy(double[] array) { if (array == null) return new double[0]; double[] newArray = new double[array.length]; System.arraycopy(array, 0, newArray, 0, array.length); return newArray; } public static float[] copy(float[] array) { if (array == null) return new float[0]; float[] newArray = new float[array.length]; System.arraycopy(array, 0, newArray, 0, array.length); return newArray; } }