<分区>
我想使用唯一 ID nhsNumber 检查患者对象是否已存在于 ArrayList 队列中。但是当我将一个我知道队列中已经存在的患者添加到队列中时,以下代码不会检测到它。知道这是为什么吗?
public boolean checkIfInQueue(Patient p) {
// set nhsNumber equal to the nhsNumberLabel on the page
String nhsNumber = nhsNumberLabel.getText();
System.out.println("Checking if " + nhsNumber + " already in the queue");
// create boolean to state whether a person is in the queue or not (defaults to false)
boolean isInQueue = false;
for (int i = 0; i < Queue.queue.size(); i++) {
if (Queue.queue.size() == 0) {
System.out.println("Queue is empty");
isInQueue = false;
break;
} else if (Queue.queue.get(i).getNhsNumber() == p.getNhsNumber()) {
System.out.println(p.getFirstName() + " is already in the queue (checkIfInQueue() method)");
isInQueue = true;
break;
} else {
System.out.println(p.getFirstName() + " is not is the queue (checkIfInQueue() method)");
isInQueue = false;
}
}
return isInQueue;
}
谢谢, K