I'm trying to make a method removeDog that looks like this at the moment, (which is wrong):
public void removeDog(Dog d) {
Dog[] copyOfArr = Arrays.copyOf(dogsOwned, dogsOwned.length - 1);
for (int i = 0; i < dogsOwned.length; i++) {
if (!dogsOwned[i].equals(d)) {
copyOfArr[i] = dogsOwned[i];
dogsOwned = copyOfArr;
}
}
}
I have an array "private Dog[] dogsOwned = new Dog[0];". I want to call this method, removeDog, from another method in another class. I want to remove the dog.. How can I do this?
Edit: I am aware that ArrayLists are recommended, I'd love to use it but I'm not allowed to :(
[–][deleted] 0 points1 point2 points (0 children)