Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

containsAll return False when comparing two ArrayList of object [duplicate]

Tags:

java

arraylist

I have two ArrayList as :

ArrayOne

ClassPojo [Name ="XXX", FilterID = 4]
ClassPojo [Name = "ZZZ", FilterID = 5]

ArrayTwo

ClassPojo [Name = "XXX", FilterID = 4]

but when try to use:

 Arrays.asList(ArrayOne).contains(ArrayTwo )

or

ArrayOne().containsAll(ArrayTwo)

it returns false, i know the comparing is based on Refrences not Values equlaty but how i can do it by values note that: i want to use conatinsAll , so if the content of arrayTwo is found in some part of ArrayOne return true .

like image 848
Hesham El-Nemr Avatar asked Oct 22 '25 03:10

Hesham El-Nemr


1 Answers

i know the comparing is based on references not Values equality

No, it is based on value equality. You need to override equals() to properly compare 2 objects of your ClassPojo

like image 163
jmj Avatar answered Oct 25 '25 16:10

jmj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!