Performs a deep copy of an array of an array of ints - Java java.lang

Java examples for java.lang:Math Array Function

Description

Performs a deep copy of an array of an array of ints

Demo Code


//package com.java2s;

public class Main {
    /**//from www  .jav a 2s  . c o  m
     * Performs a deep copy of an array of an array of ints
     * @param s
     * @return
     */
    public static int[][] clone(int[][] s) {
        int[][] d = new int[s.length][0];
        for (int i = 0; i < s.length; i++) {
            d[i] = new int[s[i].length];
            for (int j = 0; j < s[i].length; j++)
                d[i][j] = s[i][j];
        }
        return d;
    }
}

Related Tutorials