我目前有3个类,一个包含GUI的主类,其中我调用此方法,一个包含数据的客户类和一个收集客户类数据的customerList类,到数组列表中,并且还包含搜索数组列表方法。正在搜索一个ArrayList
我想实现一个搜索方法,可以从我的主要类在一个动作事件处理程序中调用。我有几个问题,但。每当我运行该方法时,“System.out.println(customer.returnFamilyName());”行总是显示我的数组列表中的第一个familyname。
不要犹豫,要了解更多信息,我不知道我已经解释了这一点。
这里是我的方法:
public void searchCustomer(String familyName) {
int index = 0;
boolean found = false;
customer customer;
while(index < CustomerList.size() && !found) {
customer = CustomerList.get(index);
if(customer.returnFamilyName().equalsIgnoreCase(familyName)) {
found = true;
break;
}
if(found == true) {
;
}
System.out.println(customer.returnFamilyName());
index++;
return;
}
}
谢谢你,关于重命名我的类和方法,我早些时候读过关于这个地方的内容,一旦我写完我的课程,我一定会这样做。 – user1080390 2012-01-03 21:34:48
为什么你在这一点上打扰布尔值?如果你找到了你要找的东西,你可以明确地将它输出到终端,然后从增强的for循环中断开,然后再断开整个方法。 – Makoto 2012-01-03 21:39:55
@Makoto,谢谢。我修复了我的代码。原始代码的所有其他问题都失去了这个错误。 – 2012-01-03 21:55:52