If it doesn't matter if data in rows are the same, but shuffled we can just store all numbers from arrays into separate Lists and then compare them.
int[][] a1 = { { 1, 2 }, { 3, 4 } };
int[][] a2 = { { 4, 3 }, { 2, 1 } };
//lists to store arrays data
List<Integer> list1 = new ArrayList<Integer>();
List<Integer> list2 = new ArrayList<Integer>();
//lest place data from arrays to lists
for (int[] tmp:a1)
for (int i:tmp)
list1.add(i);
for (int[] tmp:a2)
for (int i:tmp)
list2.add(i);
//now we need to sort lists
Collections.sort(list1);
Collections.sort(list2);
//now we can compare lists on few ways
//1 by Arrays.equals using list.toArray()
System.out.println(Arrays.equals(list1.toArray(), list2.toArray()));
//2 using String representation of List
System.out.println(list1.toString().equals(list2.toString()));
//3 using containsAll from List object
if (list1.containsAll(list2) && list2.containsAll(list1))
System.out.println(true);
else
System.out.println(false);
//and many other probably better ways
If rows also have to contain same numbers (but can be shuffled like [1,2] [2,1] but not like [1,2][1,3]) you can do something like this
// lets say i a1 and a2 are copies or original arrays
int[][] a1 = { { 1, 2 }, { 3, 4 } };
int[][] a2 = { { 4, 3 }, { 2, 1 } };
System.out.println(Arrays.deepToString(a1));// [[1, 2], [3, 4]]
System.out.println(Arrays.deepToString(a2));// [[3, 4], [1, 2]]
// lets sort data in each row
for (int[] tmp : a1)
Arrays.sort(tmp);
for (int[] tmp : a2)
Arrays.sort(tmp);
System.out.println("========");
System.out.println(Arrays.deepToString(a1));// [[1, 2], [3, 4]]
System.out.println(Arrays.deepToString(a2));// [[3, 4], [1, 2]]
// Now I want to order rows by first stored number.
// To do that I will use Array.sort with this Comparator
Comparator<int[]> orderByFirsNumber = new Comparator<int[]>() {
public int compare(int[] o1, int[] o2) {
if (o1[0] > o2[0]) return 1;
if (o1[0] < o2[0]) return -1;
return 0;
}
};
// lets sort rows by its first stored number
Arrays.sort(a1, orderByFirsNumber);
Arrays.sort(a2, orderByFirsNumber);
// i wonder how arrays look
System.out.println("========");
System.out.println(Arrays.deepToString(a1));// [[1, 2], [3, 4]]
System.out.println(Arrays.deepToString(a2));// [[1, 2], [3, 4]]
System.out.println("Arrays.deepEquals(a1, a2)="
+ Arrays.deepEquals(a1, a2));
Output
[[1, 2], [3, 4]]
[[4, 3], [2, 1]]
========
[[1, 2], [3, 4]]
[[3, 4], [1, 2]]
========
[[1, 2], [3, 4]]
[[1, 2], [3, 4]]
Arrays.deepEquals(a1, a2)=true