[Solved] JAVA – Getting differen between two arrays


First you would need to make a method in your custom class that accepts an object of the same class and tests whether the imputed object has the same values as the object which is calling the method. Then just loop through the array and see if the object is equal to another object. This has already been done in the String class. In the String class there is a method
equals(String s) which you could use

Here is an example of how you would compare 2 String arrays. To make it work with you custom class, just change the array type and make a .equals method in your class.

String[] array1={"Hello","Hi"};
String[] array2={"Hello","eat"};

for(int x=0;x<array1.length;x++){
    Boolean present=false;
    for(int y=0;y<array2.length;y++){
       if(array1[x].equals(array2[y])){
         present=true;
         break;
       }
     }
   if(!present){
      System.out.println(array1[x]);
 }
} 

EDIT:

here is how you would make your equals method in your custom class

public class custom{
int value;
String text;

public Boolean equals(custom obj){
  if(this.value==obj.value && this.text.equals(obj.text)){
  return true;
 }else{return false;}
}
}

1

solved JAVA – Getting differen between two arrays