我有一个 ArrayList,其中包含 profId、名字、姓氏、年龄等数据。
现在我有一个姓氏和名字,它来自用户表单方面。现在我想将它们与 ArrayList 进行比较。如果两者都匹配,我想检索“各自的 profId”。
例如,arraylist 包含类似的数据
profId 姓 名字 年龄
1 罗伊萨姆 25
2 ryob arnav 30
现在用户将分别输入姓氏和名字作为 roy 和 sam。我将通过他们的 getter 方法获取这些数据。
现在,我应该如何将这两个名称与 ArrayList 进行比较,这样我才能得到他的完美 profid:
'1'。
我试图通过这种方式进行比较。
// existPatList is arraylist patfamily is object of Family from where I will get users value
for(Family p : existPatList) {
System.out.println("Last name" +p.getLastName());
System.out.println("First name"+p.getFirstName());
if(p.getLastName().equalsIgnoreCase(patFamily.getLastName())) {
System.out.println("got it");
}
}
我怎么解决这个问题?