java.util.ConcurrentModificationException是什么意思?

java.util.ConcurrentModificationException异常,是因为自己不能同时修改自己

我现在做了一个 ,无限级别分类,hibernate自关联,添加商品的时候,只能添加商品类型的子节点,先查出所有的类型,然后,把没有子节点的结点(也就是子节点),放到一个集合里面,我先是这样做的

List<Types> array=goodsServiceImpl.selectType();
if (array != null) {
			for (Types arr : array) {

				if (!arr.getTypeses().isEmpty()) {
					array.remove(arr);
				}
			}
		}

 后来出现了java.util.ConcurrentModificationException这个异常,后来解决方法如下:

解决:
List<Types> type = goodsServiceImpl.selectType();
		List<Types> array =new ArrayList<Types>();
		if (type != null) {
			for (Types arr : type) {

				if (!arr.getTypeses().isEmpty()) {
					
				}else{
					array.add(arr);
				}
			}
		}

猜你喜欢

转载自hongmeikaile.iteye.com/blog/1066974