找到2个集合中相同和不同的元素
public void getCommonElement(){
List
<String> _first
=new ArrayList<String>();
_first
.add("jim");
_first
.add("tom");
_first
.add("jack");
List
<String> _second
=new ArrayList<String>();
_second
.add("jack");
_second
.add("happy");
_second
.add("sun");
_second
.add("good");
Collection exists
= new ArrayList<String>(_second
);
Collection notexists
= new ArrayList<String>(_second
);
exists
.removeAll(_first
);
System
.out
.println("_second中不存在于_set中的:"+exists
);
notexists
.removeAll(exists
);
System
.out
.println("_second中存在于_set中的:"+notexists
);
}
结果: _second中不存在于_set中的元素:[happy, sun, good] _second中存在于_set中的元素:[jack]
转载请注明原文地址: https://lol.8miu.com/read-5205.html