EDIT: closed because it seems that the code below works
I am currently facing the following problem:
I have two two-dimensional arrays, of which the second dimension always has the size 7 (max. index is therefore 6).
Now I need to compare these arrays.
I want to print out if there has been a field added or removed, at any index.
For example:
Array 1:
0|1|2|3
0 |1|2|5
1 |4|4|6
(...)
6 |6|2|8
Array 2
0|1|2|3|4
0 |1|1|2|5
1 |4|4|4|6
(...)
6 |6|7|2|8
As you can see, I have added a column to the second array.
Now I need to print out this column or add it to an array list.
The same has to happen when a column gets removed or changed.
How can I achieve that?
My code so far:
static List<String[]> differences;
static List<String[]> checkForDifferences(String[][] tableOld,String[][] tableNew) {
differences = new ArrayList<String[]>();
if(!Arrays.deepEquals(tableNew,tableOld)) {
for(int hour = 0; hour < tableOld.length;hour++) {
try {
boolean removed = true;
for(int hour2 = 0;hour2 < tableNew.length;hour2++)
if(Arrays.equals(tableOld[hour],tableNew[hour2]))
removed = false;
if(removed)
differences.add(new String[]{"-",tableOld[hour][0], tableOld[hour][1], tableOld[hour][2], tableOld[hour][3], tableOld[hour][4], tableOld[hour][5], tableOld[hour][6]});
} catch (ArrayIndexOutOfBoundsException e){
e.printStackTrace();
break;
}
}
for (int hour = 0; hour < tableNew.length; hour++) {
try {
boolean added = true;
for (int hour2 = 0; hour2 < tableOld.length; hour2++)
if (Arrays.equals(tableNew[hour], tableOld[hour2]))
added = false;
if (added)
differences.add(new String[]{"+", tableNew[hour][0], tableNew[hour][1], tableNew[hour][2], tableNew[hour][3], tableNew[hour][4], tableNew[hour][5], tableNew[hour][6]});
} catch (ArrayIndexOutOfBoundsException e) {
e.printStackTrace();
break;
}
}
return differences;
} else {
return null;
}
}