Java中的Set类差集问题?差集为啥是1,2不是1,2,8,9,;
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java中的Set类差集问题?差集为啥是1,2不是1,2,8,9,;相关的知识,希望对你有一定的参考价值。
public static void main(String[]args)
Set<Integer>set1=Sets.newHashSet(1,2,3,4,5,6);
Set<Integer>set2=Sets.newHashSet(3,4,5,6,7,8,9);
System.out.println("交集为:");
Set<Integer>S=Sets.difference(set1, set2);
for(Integer temp:S)
System.out.println(temp);
/**
* Returns an unmodifiable view of the difference of two sets. The
* returned set contains all elements that are contained by set1 and
* not contained by set2. set2 may also contain elements not
* present in set1; these are simply ignored. The iteration order of
* the returned set matches that of set1.
*
* Results are undefined if set1 and set2 are sets based
* on different equivalence relations (as HashSet, TreeSet,
* and the keySet of an IdentityHashMap all are).
*/ 参考技术A Sets.difference用于求两个集合的差集,结果集合中包含所有属于第一个集合
但不属于第二个集合的元素。 参考技术B Sets.difference(set1, set2);
这个方法的代码是怎样的
~~~~~~~~~~~~~追问
在补充问题里
以上是关于Java中的Set类差集问题?差集为啥是1,2不是1,2,8,9,;的主要内容,如果未能解决你的问题,请参考以下文章