开发者社区> 问答> 正文

JAVA中Commons Collections - Union如何理解?

JAVA中Commons Collections - Union如何理解?

展开
收起
vncamyi27xznk 2021-11-13 23:54:25 348 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(""Union of List 1 and List 2: "" + CollectionUtils.union(list1, list2)); } })

    它将打印以下结果: console.log(List 1: [A, A, A, C, B, B] List 2: [A, A, B, B] Union of List 1 and List 2: [A, A, A, B, B, 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 立即下载