我正在驗證我的數據列表與文件中的數據在數據庫中,以避免在數據庫中重複插入,如果重複存在,那麼我想索引該文件中的記錄,上午使用下面的代碼,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