利用Stack倒序List,利用Set是List不能添加重复元素


利用Stack倒序List


Stack<Contact> stactContact = new Stack<Contact>();
for (Contact contact : mFollowerList) {
stactContact.push(contact);
}
while (!stactContact.empty()) {
mContactList.add(stactContact.pop());
}


利用Set使List不能添加重复元素


//排除重复元素
Set tempSet = new HashSet(mFollowerList);
if (tempSet.add(addFollower)) {
mFollowerList.add(addFollower);
}


友情提醒,new collection的时候都要判空