Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the different elements between two ArrayLists in Java

Tags:

java

arraylist

How can I know the different element between 2 array list in java? I need the exact element not a Boolean value which can be retrieved using removeAll().

like image 571
zhrani Avatar asked May 17 '11 00:05

zhrani


1 Answers

Use Apache Commons Collections (javadoc):

CollectionUtils.disjunction(a, b);

See also: Effective Java, 2nd edition, Item 47: Know and use the libraries (The author mentions only the JDK's built-in libraries but I think the reasoning could be true for other libraries too.)

like image 111
palacsint Avatar answered Sep 23 '22 03:09

palacsint