[英]How do I update a specific property of an object in an arraylist in Java?
我有一個為學校項目制作的系統,包括客戶、約會等。我只是在努力弄清楚如何更新我為每個客戶設置的 LocalDateTime 約會變量,我知道如何制作有一個新客戶,但不知道如何更新它。
ArrayList<Client> clients = Client.inputClientsFromFile();
LocalDateTime tempappointment;
int yearint = Integer.parseInt(year.getText());
int monthint = Integer.parseInt(month.getText());
int dayint = Integer.parseInt(day.getText());
int hourint = Integer.parseInt(hour.getText());
int minuteint = Integer.parseInt(minutes.getText());
tempappointment = LocalDateTime.of(yearint,monthint,dayint,hourint,minuteint);
我寫這個是為了從文本框和這個獲取本地日期時間
public LocalDateTime getAppointment() {
return nextappointment;
}
/**
* @param nextappointment
*/
public void setAppointment(LocalDateTime nextappointment) {
this.nextappointment = nextappointment;
在 arraylist 中初始化客戶端對象時。
您需要調用Client.setAppointment
對於特定客戶:
LocalDateTime tempappointment = LocalDateTime.of(yearint, monthint, dayint, hourint, minuteint);
clients.get(0).setAppointment(tempappointment);
對所有人
for (Client client : clients) {
client.setAppointment(tempappointment);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.