I am trying to create a clear method that would clear the array I have, I've seen that using a clear method is what I need but I cannot seem to use it?
list.clear();
What I think I have to do:
public void clear() {
return doctors.clear();
}
doctors are an array by the way.
However I think I am thinking about this incorrectly..
An array is not a List. There is no clear method. You can clear one by assigning a null reference, and let the garbage collector take care of it...
yourArray = null;
or create a new array, and replace the old with the new. The old one will be garbage collected.
yourArray = new YourObject[n];
You can simply create a new empty array and assign that:
doctors = new Doctor[size];
The array will be defined but the objects will not be created yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With