Reputation: 11
public class Patient extends Person {
private String Diagnosis;
private Appointment[] appointment = new Appointment[2];
private int numberofAppointment;
public static int numberOfPatient;
public void DellappointmentAT(int index) {
appointment[index].setAvailable(true);
numberofAppointment--;
}
}
The class i created, has an Array of object as data fields and i have this method that should remove an element from this array, I want to delete the element without changing the array size.
Upvotes: 1
Views: 71
Reputation: 9650
How about this:
public void DellappointmentAT(int index) {
appointment[index].setAvailable(true);
numberofAppointment--;
for (int i = index; i < numberofAppointment; ++i) {
appointment[i] = appointment[i+1];
}
}
Upvotes: 0
Reputation: 340
Removing an element will impact the array size.
If you really need the initial array to stay the same, there are 2 common approaches:
Upvotes: 1