JAVA List 合併去重

List<A>和List<B>,A/B中均沒有重複的,現在保證A/B合併爲C,且C中沒有重複的。


參考http://blog.csdn.net/secondjanuary/article/details/8599108

A.removeAll(B)

A.addAll(B)

(此處建議處理A爲空的情況)


一個同事的建議

Set<Long> C = new HashSet<>();

C.addAll(A);

C.addAll(B);

new ArrayList<Long>(C);//set轉list

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章