for循环里面使用iterator进行遍历,如果把iterator定义到for循环外面,会造成iterator只循环一次

下面这种情况,就会造成iterator内层循环只遍历一次
	Iterator it = jsonObject.keys(); 
    for (ProjectFeeCardBudget feeCardBudget : feeCardBudgetList) {
		while(it.hasNext()){
			// 获得key
			String key = it.next(); 
			String value = jsonObject.getString(key);    
            if(key.equals(feeCardBudget.getSubjectCode())){               	
           	 ProjectFeeCardBudget projectFeeCardBudget = new ProjectFeeCardBudget();
           	 projectFeeCardBudget.setProjectId(vProjectId);
           	 projectFeeCardBudget.setSubjectCode(feeCardBudget.getSubjectCode());
           	 projectFeeCardBudget.setSubjectFee(Double.parseDouble(value)*(-1));
           	 projectFeeCardBudget.setSubjectName(feeCardBudget.getSubjectName());
           	 projectFeeCardBudget.setFeeChargerId(feeCardBudget.getFeeChargerId());
           	 projectFeeCardBudget.setFeeCardNum(feeCardBudget.getFeeCardNum());
           	 projectFeeCardBudget.setProjectIncomeId(projectIncome.getId());
           	 projectFeeCardBudget.setBudgetType(feeCardBudget.getBudgetType());
           	 feeBudgetList.add(projectFeeCardBudget);  
            }
      }	
	}

应该把iterator定义到for外层循环里面
for循环里面使用iterator进行遍历,如果把iterator定义到for循环外面,会造成iterator只循环一次_第1张图片

你可能感兴趣的:(java)