java.util.ConcurrentModificationException:“当这种修改是不允许的时,检测到对象的并发修改的方法可能会抛出此异常。”
知道为什么我的 set 方法会出现此异常吗?
private ArrayList<Double> voltagesList = new ArrayList<Double>();
private ArrayList<String> devicesList = new ArrayList<String>();
public void setVoltage(String device, double voltage) {
for(String d: devicesList){
if(d.equals(device)){
voltagesList.set(devicesList.indexOf(device), voltage);
}
else{
voltagesList.add(voltage);
devicesList.add(device);
}
}
}