Returns a deep clone of a 2D boolean array. - Java Collection Framework

Java examples for Collection Framework:Array Clone

Description

Returns a deep clone of a 2D boolean array.

Demo Code


//package com.java2s;

public class Main {
    /**//from  w w  w.j a  va 2s.c o  m
     * Returns a deep clone of a 2D boolean array.
     * 
     * @param src   The 2D-array to clone
     * @return      | deepEquals(result, src)
     * @return      | !src.equals(result)
     * @return      | for each int rowNumber in 0..src.lenght-1:
     *             |   !src[rowNumber].equals(result[rowNumber])
     */
    public static boolean[][] deepClone(boolean[][] src) {
        assert (src != null);
        boolean[][] dest = new boolean[src.length][];
        for (int i = 0; i < src.length; i++) {
            dest[i] = src[i].clone();
        }
        return dest;
    }
}

Related Tutorials