1.先要读取Excel里的数据得到List<String,Object> dataFromExcel
2.直接上代码(如下)
private List<Map<String,Object>> removeRepeatData(List<Map<String,Object>> dataFromExcel,String field){
List<Map<String,Object>> tmpList=new ArrayList<Map<String,Object>>();
Set<String> keysSet = new HashSet<String>();
for(Map<String,Object> map :dataFromExcel) {
String keys = (String) map.get(field);
int beforeSize = keysSet.size();
keysSet.add(keys);
int afterSize = keysSet.size();
if(afterSize == beforeSize + 1){
tmpList.add(map);
}
}
return tmpList;
}
3.参数:dataFromExcel读取的Excel数据 field:根据某个字段去重
网友评论