栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

字符串列表比较器

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

字符串列表比较器

Collection firstList = new ArrayList() {{    add("str1");    add("str2");}};Collection secondList = new ArrayList() {{    add("str1");    add("str3");    add("str4");}};System.out.println("First List: " + firstList);System.out.println("Second List: " + secondList);// Here is main partsecondList.removeAll(firstList);System.out.println("Result: " + secondList);

更新: 更复杂的代码版本

Collection<String> firstList = new ArrayList<String>();firstList.add("str1");firstList.add("str2");Collection<String> secondList = new ArrayList<String>();secondList.add("str1");secondList.add("str2");secondList.add("str3");System.out.println("First List: " + firstList);System.out.println("Second List: " + secondList);// Here is main partsecondList.removeAll(firstList);

更新:

要获得两个字符串列表之间的实际差异,请执行此操作。

    Set<String> setOne = new HashSet<String>(); Set<String> setTwo = new HashSet<String>();    setOne.add("1");    setOne.add("2");    setOne.add("5");    setTwo.add("1");    setTwo.add("3");    setTwo.add("4");    Set<String> setTwoDummy = new HashSet<String>(setTwo);    setTwo.retainAll(setOne); setTwoDummy.addAll(setOne);    setTwoDummy.removeAll(setTwo);    System.out.println(""+setTwoDummy);


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/470094.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号