【发布时间】:2013-10-01 11:03:27
【问题描述】:
我有 2 个 HashMap<Integer,Point3D> 对象名称是 positiveCoOrdinate and negativeCoOrdinates。
我正在使用以下条件检查PositiveCoOrdinates。如果它满足添加到negativeCoOrdinates 并从positiveCoOrdinates 中删除的对应点。
HashMap<Integer, Point3d> positiveCoOrdinates=duelList.get(1);
HashMap<Integer, Point3d> negativecoOrdinates=duelList.get(2);
//condition
Set<Integer> set=positiveCoOrdinates.keySet();
for (Integer pointIndex : set) {
Point3d coOrdinate=positiveCoOrdinates.get(pointIndex);
if (coOrdinate.x>xMaxValue || coOrdinate.y>yMaxValue || coOrdinate.z>zMaxValue) {
negativecoOrdinates.put(pointIndex, coOrdinate);
positiveCoOrdinates.remove(pointIndex);
}
}
在添加、删除时间时出现以下错误。
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(Unknown Source)
at java.util.HashMap$KeyIterator.next(Unknown Source)
at PlaneCoOrdinates.CoordinatesFiltering.Integration(CoordinatesFiltering.java:167)
at PlaneCoOrdinates.CoordinatesFiltering.main(CoordinatesFiltering.java:179)
对于我的测试,我在If 条件中提到了System.out.println(coOrdinate.x); 语句。它工作正常。
如果我在 If 条件中添加 2 行(我上面提到的),它会抛出错误。
我该如何解决这个问题。
谢谢。
【问题讨论】:
-
使用
entrySet()可以避免查找刚刚获得的密钥
标签: java