• Post Reply Bookmark Topic Watch Topic
  • New Topic

Comparing Two ArrayLists Objects  RSS feed

 
k sabeerdeen
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi..

i have two arraylists namely list1 & list2
list1 contains 5 objects (name,id,department)
list2 contains 7 objects (name,id,department) in that 7 objects, 2 objects are same as objects present in list1
i need to eliminate that 2 objects from list2
help me to acheive this

thanks in advance!
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A simple solution would be to loop through the first list and call List#remove(Object) on the second. (and making sure that the objects contained in the list properly override the equals() method).
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is also one inbuilt method in List. you can use that


and as christophe said make sure that the objects contained in the list are override the equals() method
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot about removeAll...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!