1、去掉List中重复的元素
利用Set集合中元素唯一的特性,使用List构造出来的Set将会去掉List中重复的元素。
new HashSet(List exampleList)
2、利用Map<key,value>的键值唯一的特性
Map<Object,Integer> map = new HashMap<Object,Integer>();
for(int i = 0 ; i < yourList.size() ; i++){
map.put(yourList.get(i) , i);
}
Set keySet = map.keySet(); 如此同样能对List中的元素去重。