甲Rec
對象具有稱爲tag
一個成員變量這是一個String
。如何重複數據刪除的對象的列表?
如果我有一個List
的Rec
s,我怎麼能根據tag
成員變量取消這個列表?
我只需要確保該List
只包含一個Rec
每個tag
值。
類似下面的,但我不知道什麼是最好的算法來跟蹤計數等:
private List<Rec> deDupe(List<Rec> recs) {
for(Rec rec : recs) {
// How to check whether rec.tag exists in another Rec in this List
// and delete any duplicates from the List before returning it to
// the calling method?
}
return recs;
}
如果你問我怎麼從列表中刪除重複的,這已經被問過很多次;的[刪除從列表重複] http://stackoverflow.com/search?q=[java]+removing+duplicates – Qwerky 2010-11-03 14:52:58
可能重複(http://stackoverflow.com/questions/2849450/remove-duplicates-from-a -list) – 2010-11-03 14:55:41