大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
如下英文是Guava中注释原文。意思是说该方法返回只存在于set1独有的数据,至于set2中独有数据和set1和set2交集的数据直接忽略。而且返回的只是不可变的Set视图,不会修改原set中数据。
创新互联一直秉承“诚信做人,踏实做事”的原则,不欺瞒客户,是我们最起码的底线! 以服务为基础,以质量求生存,以技术求发展,成交一个客户多一个朋友!为您提供成都网站设计、做网站、成都网页设计、微信小程序定制开发、成都网站开发、成都网站制作、成都软件开发、重庆APP开发公司是成都本地专业的网站建设和网站设计公司,等你一起来见证!
/**
* 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).
*/
public static void main(String[] args) {
Integer[] A = {1,2,3,4};
Integer[] B = {1,3,7,9,11};
ListInteger listA = Arrays.asList(A);
ListInteger listB = Arrays.asList(B);
ListInteger jiaoji = new ArrayListInteger();
for(Integer a:listA){
if(listB.contains(a)){
jiaoji.add(a);
}
}
System.out.println(jiaoji);
ListInteger bingji = new ArrayListInteger();
for(Integer a:listA){
if(!bingji.contains(a)){
bingji.add(a);
}
}
for(Integer b:listB){
if(!bingji.contains(b)){
bingji.add(b);
}
}
System.out.println(bingji);
ListInteger chaji = new ArrayListInteger();
for(Integer a:listA){
if(!listB.contains(a)){
chaji.add(a);
}
}
System.out.println(chaji);
}
import java.util.*;
public class ArrayTest {
public static void main(String[] args) {
int[] a = {1,6,4,5,2,3,};
int[] b = {2,3,4,56,7,8,99};
int[] t = ArrayTest.并集(a, b);
for(int i:t)System.out.print(i+" ");
System.out.println();
t = ArrayTest.交集(a, b);
for(int i:t)System.out.print(i+" ");
}
static int[] 并集(int[] a,int[] b){
Arrays.sort(a);
Arrays.sort(b);
int[] t = new int[a.length];
System.arraycopy(a,0,t,0,t.length);
out:
for(int i:b){
for(int j:a){
if(i==j)continue out;
}
t=putInt(t,i);
}
Arrays.sort(t);
return t;
}
static int[] 交集(int[] a,int[] b){
Arrays.sort(a);
Arrays.sort(b);
int[] t = new int[0];
for(int i:a){
for(int j:b){
if(i==j){
t=putInt(t,i);
break;
}
}
}
return t;
}
static int[] putInt(int[] a,int i){
int[] t = new int[a.length+1];
System.arraycopy(a, 0,t,0,a.length);
t[a.length]=i;
return t;
}
}
//做了交集,并集,差集自己想吧