简体   繁体   中英

How do I update a specific property of an object in an arraylist in Java?

I have a system that I'm making for a school project, with clients, appointments, etc. I'm just struggling to figure out how I can update the LocalDateTime appointment variable that I have setup for each client, I know how to make a new client with one, but just can't figure out how to update it.

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);

I have written this to get the localdatetime from textboxes and this

public LocalDateTime getAppointment() {
        return nextappointment;
    }

    /**
     * @param nextappointment
     */
    public void setAppointment(LocalDateTime nextappointment) {
        this.nextappointment = nextappointment;

when initiliazing the client object in the arraylist.

You need to call Client.setAppointment

For a specific client:

LocalDateTime tempappointment = LocalDateTime.of(yearint, monthint, dayint, hourint, minuteint);
clients.get(0).setAppointment(tempappointment);

For all

for (Client client : clients) {
    client.setAppointment(tempappointment);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM