I have a custom class called alphabets.
public class Alphabets {
String alp;
public Alphabets(String alp) {
this.alp = alp;
}
public String getAlp() {
return alp;
}
}
I have two ArrayLists
containing custom objects or type (String
& Alphabets
) each.
ArrayList<Object> ar = new ArrayList<>();
ArrayList<Object> br = new ArrayList<>();
Alphabets a = new Alphabets("A");
Alphabets b = new Alphabets("B");
Alphabets b_clone = new Alphabets("B");
ar.add(a);
ar.add(b);
br.add(b_clone);
System.out.println(ar.contains(br.get(0)));
The output is false which technically correct but the actual value contained in the objects are equal ("B" in this case).This of course is just a snippet of the code.I need to check two entire ArrayLists
to see if one lists contains objects from the other list and therefore cannot use the inbuilt .contains function.
Is there a quick method or any solution actually for solving this?