集合中对象去重
- HashMap
Kill kill1 = new Kill();
Kill kill2 = new Kill();
Map<String, Object> mapList = new HashMap<>();
List<Kill> killList = new ArrayList<>();
killList.add(kill1);
killList.add(kill2);
for (Kill kill : killList) {
if (!mapList.containsKey("" + kill.toString().hashCode())) {
mapList.put(kill.toString().hashCode() + "", kill);
}
}
for (Object kill : mapList.values()){
System.out.println(kill);
}
网友评论