I am trying to compare two arrays of objects to verify that they have the same values. It is returning false when it should be returning true. Im not sure what I am doing wrong when comparing the two arrays.
Class : arrayObject
import java.util.*;
public class arrayObject {
private int initializedInt;
private boolean equals;
private int[] one, two;
arrayObject(){
}
arrayObject(int x){
initializedInt = x;
}
public int getInt(){
return initializedInt;
}
public boolean equals(arrayObject[] one,arrayObject[] two, int sizeOfArray){
equals = Arrays.equals(one, two);
//while(equals){
/*for (int i = sizeOfArray; i !=0; i--){
one[i].equals(two[i]);
return equals;
}*/
//}
return equals;
}
}
Class : Main
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
int sizeOfArray = 3;
arrayObject arrayEqualsMethodTest = new arrayObject();
arrayObject[] array1 = new arrayObject[sizeOfArray];
arrayObject[] array2 = new arrayObject[sizeOfArray];
System.out.print("Array1 can be resolved to {");
for(int i = 0; i != 3; i++){
array1[i] = new arrayObject(4);
System.out.print(array1[i].getInt() + ",");
}
System.out.print("}");
System.out.print("\nArray2 can be resolved to {");
for(int i = 0; i != 3; i++){
array2[i] = new arrayObject(4);
System.out.print(array2[i].getInt() + ",");
}
System.out.print("}");
System.out.println("\nDoes array1 equal array2? " + Arrays.equals(array1, array2));
System.out.println("That doesn't seem right. Lets run it through an equals method!\n"
+ "Does array1 equal array2 when run through the method? "
+ arrayEqualsMethodTest.equals(array1, array2, sizeOfArray));
}
}