我正在验证我的数据列表与文件中的数据在数据库中,以避免在数据库中重复插入,如果重复存在,那么我想索引该文件中的记录,上午使用下面的代码,ArrayList的indexOf()在java中返回-1
List<StudentMaster> studentMasterListFromDB = studentMasterDao.getStudentList();
List<StudentMasterVO> studentMasterListFromFile = getStudentMasterListFromFile();
for(int index=0;index<studentMasterListFromDB.size();index++){
StudentMasterVO studentMasVO = new StudentMasterVO();
StudentMaster studentMaster = studentMasterListFromDB.get(index);
BeanUtils.copyProperties(studentMasVO, studentMaster);
int indexOfexistingRec = studentMasterListFromFile.indexOf(studentMasVO);
System.out.println("indexOfexistingRec :"+indexOfexistingRec);
}
但“indexOfexistingRec”值给出-1,而不是现有记录索引的索引。
'-1'建议您正在寻找的项目没有被发现。 – devnull
感谢您的回复。在我的列表中,搜索记录存在,但它显示-1。 – user2507974
对不起,这是BeanUtils.copyProperties()方法。 – user2507974