Java Array Clone clone(boolean[] array)

Here you can find the source of clone(boolean[] array)

Description

clone

License

Apache License

Declaration

public static boolean[] clone(boolean[] array) 

Method Source Code

//package com.java2s;
/*//from  w  ww .j  a  va  2  s . com
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 boolean[] clone(boolean[] array) {
        boolean[] newArray = new boolean[array.length];

        System.arraycopy(array, 0, newArray, 0, array.length);

        return newArray;
    }

    public static boolean[] clone(boolean[] array, int from, int to) {
        boolean[] newArray = new boolean[to - from];

        System.arraycopy(array, from, newArray, 0, Math.min(array.length - from, newArray.length));

        return newArray;
    }

    public static byte[] clone(byte[] array) {
        byte[] newArray = new byte[array.length];

        System.arraycopy(array, 0, newArray, 0, array.length);

        return newArray;
    }

    public static byte[] clone(byte[] array, int from, int to) {
        byte[] newArray = new byte[to - from];

        System.arraycopy(array, from, newArray, 0, Math.min(array.length - from, newArray.length));

        return newArray;
    }

    public static char[] clone(char[] array) {
        char[] newArray = new char[array.length];

        System.arraycopy(array, 0, newArray, 0, array.length);

        return newArray;
    }

    public static char[] clone(char[] array, int from, int to) {
        char[] newArray = new char[to - from];

        System.arraycopy(array, from, newArray, 0, Math.min(array.length - from, newArray.length));

        return newArray;
    }

    public static double[] clone(double[] array) {
        double[] newArray = new double[array.length];

        System.arraycopy(array, 0, newArray, 0, array.length);

        return newArray;
    }

    public static double[] clone(double[] array, int from, int to) {
        double[] newArray = new double[to - from];

        System.arraycopy(array, from, newArray, 0, Math.min(array.length - from, newArray.length));

        return newArray;
    }

    public static float[] clone(float[] array) {
        float[] newArray = new float[array.length];

        System.arraycopy(array, 0, newArray, 0, array.length);

        return newArray;
    }

    public static float[] clone(float[] array, int from, int to) {
        float[] newArray = new float[to - from];

        System.arraycopy(array, from, newArray, 0, Math.min(array.length - from, newArray.length));

        return newArray;
    }

    public static int[] clone(int[] array) {
        int[] newArray = new int[array.length];

        System.arraycopy(array, 0, newArray, 0, array.length);

        return newArray;
    }

    public static int[] clone(int[] array, int from, int to) {
        int[] newArray = new int[to - from];

        System.arraycopy(array, from, newArray, 0, Math.min(array.length - from, newArray.length));

        return newArray;
    }

    public static long[] clone(long[] array) {
        long[] newArray = new long[array.length];

        System.arraycopy(array, 0, newArray, 0, array.length);

        return newArray;
    }

    public static long[] clone(long[] array, int from, int to) {
        long[] newArray = new long[to - from];

        System.arraycopy(array, from, newArray, 0, Math.min(array.length - from, newArray.length));

        return newArray;
    }

    public static short[] clone(short[] array) {
        short[] newArray = new short[array.length];

        System.arraycopy(array, 0, newArray, 0, array.length);

        return newArray;
    }

    public static short[] clone(short[] array, int from, int to) {
        short[] newArray = new short[to - from];

        System.arraycopy(array, from, newArray, 0, Math.min(array.length - from, newArray.length));

        return newArray;
    }
}

Related

  1. clone(boolean[] array)
  2. clone(boolean[] in)
  3. clone(byte[] input)
  4. clone(byte[] orig)
  5. clone(byte[][] im)