Finding the different elements between two ArrayLists in Java

后端 未结 6 1277
滥情空心
滥情空心 2021-02-06 05:43

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().

6条回答
  •  爱一瞬间的悲伤
    2021-02-06 06:24

    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.)

提交回复
热议问题