List difference in java

前端 未结 11 1788
野的像风
野的像风 2020-11-30 04:33

I have two ArrayList as follows:

original: 12, 16, 17, 19, 101

selected: 16, 19, 107, 108, 109

11条回答
  •  不知归路
    2020-11-30 05:02

    Using Guava library:

    List listA = Lists.newArrayList(12,16,17,19,101);
    List listB = Lists.newArrayList(16,19,107,108,109);
    Set intersection = Sets.intersection(Sets.newHashSet(listA), Sets.newHashSet(listB));
    listA.removeAll(intersection);
    listB.removeAll(intersection);
    

提交回复
热议问题