1 可以直接循环list,放到一个新list里
2 利用set
public List removeDeuplicate(List arlList)
{
HashSet h=new HashSet(arlList);
arlList.clear();
arlList.addAll(h);
List list=new ArrayList();
list=arlList;
return list;
}
3 用Collections的frequency方法
private List<String> removeDuplicate(List<String> list)
{
List<String> result = new ArrayList<String>();
for (String s : list)
{
if (Collections.frequency(result, s) < 1)
result.add(s);
}
return result;
}
时间: 2024-10-18 11:14:22