我正在做一些过去的试卷,为即将到来的考试做准备,并且遇到了这个问题,我不知道如何解决它,我已经编写了一个带有 if 语句的 for-each 循环,但是我不确定标题是什么以及返回什么。任何帮助都会很棒。谢谢。
问题:
An ArrayList named classList is used to store Student objects.
Write code for a method that determines whether or not data for a student with given forename and surname is present in classList.
最佳答案
类似于:
boolean lala( Student given ) {
for( Student s : classList ) {
if( s.getForename().equals( given.getForename() ) &&
s.getSurname().equals( given.getSurname() ) ) {
return true;
}
}
return false;
}
关于java - 数组列表搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6220323/