Array equals 2D - Java Collection Framework

Java examples for Collection Framework:Array Element

Description

Array equals 2D

Demo Code


//package com.java2s;

public class Main {

    public static boolean equals2D(int[][] array1, int[][] array2) {

        if (array1.length != array2.length) {

            System.err.println("Array length mismatch.");
            return false;

        }// if(...)

        for (int i1 = 0; i1 < array1.length; i1++) {

            if (array1[i1].length != array2[i1].length) {

                System.err/* ww w .  j ava2s  . c om*/
                        .println("Array length ( of 2nd Dimension ) mismatch.");

                return false;

            }// if(...)

            for (int i2 = 0; i2 < array1[i1].length; i2++) {

                if (array1[i1][i2] != array2[i1][i2]) {

                    System.err.println("Value mismatch.");
                    System.err.println("\t" + i1 + "," + i2 + "  "
                            + array1[i1][i2] + " != " + array2[i1][i2]);
                    return false;

                }// if(...)

            }// for(..i2..)

        }// for(..i1..)

        return true;

    }
}

Related Tutorials