字符串列表比较器

字符串列表比较器,第1张

字符串列表比较器
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);


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5461937.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存