ツールの種類を記録して、List集合の中のmap対象の中のvalueの値を重要にします。 4749 ワード java リスト map valueが重いです package .warning.util; import java.util.*; /** * TODO: map * @author * @version 1.0 * @description TODO * @date 2019/10/18 18:08 **/ public class ListMapUtil { public static List> toDistinctList(List> list) { // set , set , Set keysSet = new HashSet(); // String equipmentNo = ""; String depotName = ""; Iterator> it=list.iterator(); while(it.hasNext()) { Map map=it.next(); // key equipmentNo = (String) map.get("equipmentNo"); depotName = (String) map.get("depotName"); // , equals hashcode DispatchCommandsPo dispatchCommandsPo = new DispatchCommandsPo(); dispatchCommandsPo.setEquipmentNo(equipmentNo); dispatchCommandsPo.setDepotName(depotName); int beforeSize = keysSet.size(); keysSet.add(dispatchCommandsPo); int afterSize = keysSet.size(); // set ( set , map ) if(afterSize != (beforeSize + 1)) { it.remove(); } } return list; } static class DispatchCommandsPo { private String equipmentNo; private String depotName; public String getEquipmentNo() { return equipmentNo; } public void setEquipmentNo(String equipmentNo) { this.equipmentNo = equipmentNo; } public String getDepotName() { return depotName; } public void setDepotName(String depotName) { this.depotName = depotName; } // hashcode @Override public int hashCode() { int result = 17; result = 31 * result + (equipmentNo == null ? 0 : equipmentNo.hashCode()); result = 31 * result + (depotName == null ? 0 : depotName.hashCode()); return result; } // equals @Override public boolean equals(Object obj) { if (obj instanceof DispatchCommandsPo) { DispatchCommandsPo dispatchCommandsPo = (DispatchCommandsPo) obj; if (equipmentNo.equalsIgnoreCase(dispatchCommandsPo.getEquipmentNo().trim()) && depotName.equalsIgnoreCase(dispatchCommandsPo.getDepotName().trim())) { return true; } } return false; } } public static List> toDistinctList2(List> list) { // set , set , Set keysSet = new HashSet(); // String fenceName = ""; Iterator> it=list.iterator(); while(it.hasNext()) { Map map=it.next(); // key fenceName = (String) map.get("fenceName"); // , equals hashcode DispatchCommandsPo2 dispatchCommandsPo2 = new DispatchCommandsPo2(); dispatchCommandsPo2.setFenceName(fenceName); int beforeSize = keysSet.size(); keysSet.add(dispatchCommandsPo2); int afterSize = keysSet.size(); // set ( set , map ) if(afterSize != (beforeSize + 1)) { it.remove(); } } return list; } static class DispatchCommandsPo2 { private String fenceName; public String getFenceName() { return fenceName; } public void setFenceName(String fenceName) { this.fenceName = fenceName; } // hashcode @Override public int hashCode() { int result = 17; result = 31 * result + (fenceName == null ? 0 : fenceName.hashCode()); return result; } // equals @Override public boolean equals(Object obj) { if (obj instanceof DispatchCommandsPo2) { DispatchCommandsPo2 dispatchCommandsPo2 = (DispatchCommandsPo2) obj; if (fenceName.equalsIgnoreCase(dispatchCommandsPo2.getFenceName().trim())) { return true; } } return false; } } } 六@Resourceで属性組立を完成しました。 Javaマルチスレッドの実現方式とライフサイクル