开发者社区> 问答> 正文

JAVA中Commons Collections - Subtraction如何理解?

JAVA中Commons Collections - Subtraction如何理解?

展开
收起
vncamyi27xznk 2021-11-13 23:53:12 413 0
1 条回答
写回答
取消 提交回答
  • "通过从其他集合中减去一个集合的对象来获取新集合: console.log(import java.util.Arrays; import java.util.List; import org.apache.commons.collections4.CollectionUtils; public class CollectionUtilsTester { public static void main(String[] args) { //checking inclusion List<String> list1 = Arrays.asList(""A"",""A"",""A"",""C"",""B"",""B""); List<String> list2 = Arrays.asList(""A"",""A"",""B"",""B""); System.out.println(""List 1: "" + list1); System.out.println(""List 2: "" + list2); System.out.println(""List 1 - List 2: "" + CollectionUtils.subtract(list1, list2)); } })

    它将打印以下结果: console.log(List 1: [A, A, A, C, B, B] List 2: [A, A, B, B] List 1 - List 2: [A, C])

    资料来源:《Java工程师成神之路(基础篇)》,链接:https://developer.aliyun.com/topic/download?id=923"

    2021-11-16 15:41:52
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载