gpt4 book ai didi

java - 检查对象是否已存在于 Java ArrayList 中

转载 作者:搜寻专家 更新时间:2023-11-01 03:21:22 24 4
gpt4 key购买 nike

<分区>

我想使用唯一 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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com