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
arrayis not aList. There is noclearmethod. 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];