最初,我将在页面中选择学生姓名列表并提交以获取地址详细信息。学生姓名将存储在 studentDetailMapList 中。在遍历列表时,我会将学生姓名与 AddressDetailsMap 进行比较以检索地址详细信息。但是当有同名的学生时,第一次迭代返回确切的地址,但是当第二次迭代发生时,它再次返回第一个学生地址而不是第二个学生地址。它正在获取重复值
for (i=studentDetailMapList.values().iterator;i.hasNext();)
{
detailMap = (Map)i.Next();
sDetails = (StudentDetails)detailMap.get("Student");
student = sDetails.getRollNo();
StudentAddressDetails studentAddressDetails = getDetailswithAddress(AddressDetailsMap,sDetails);
}
private StudentAddressDetails getDetailswithAddress(Map AddressDetailsMap,sDetails student)
{
StudentAddressDetails addDetails = null;
try{
for(Iterator itr = AddressDetailsMap.values().iterator();itr.hasNext();){
addDetails = (StudentAddressDetails )itr.next();
if( (addDetails != null) && (addDetails.getStudentID().equals(student.getId()))){
return addDetails;
}
}
}catch(Throwable t){
return null;
}
return null;
}
与地图比较时有没有办法避免重复?非常感谢。