map與list的交集、補集操做

Listrem

boolean retainAll = arrayList.retainAll(arrayList2); //交集 只能作一次
boolean removeAll = arrayList.removeAll(arrayList2); //補集 只能作一次 List

 

Mapmap

boolean removeAll = map2.keySet().removeAll(map.keySet());//補集 只能作一次 數據

boolean retainAll = map2.keySet().retainAll(map.keySet());//交集 只能作一次hosts

 

注意:以上操做都會改變 調用removeAll和retainAll的集合,操做前最好先進行數據拷貝集合

 

MAP

hosts_temp_map.clear();
hosts_temp_map.putAll(HOSTS_MAP);

 

List

arrayList_temp.addAll(arrayList); 

相關文章
相關標籤/搜索