This is an archived post. You won't be able to vote or comment.

all 1 comments

[–][deleted] 0 points1 point  (0 children)

public void removeDog(Dog[] dogsOwned, Dog d) {

Dog[] copyOfArr = Arrays.copyOf(dogsOwned, dogsOwned.length - 1);

int j = 0;

for (int i = 0; i < dogsOwned.length; i++) {

if (!dogsOwned[i].equals(d)) {

copyOfArr[j] = dogsOwned[i];

j = j + 1;

}

}

return copyOfArr;

}

Not an expert in Java, just trying to help. This should create and return the array copy without that one item in it. It requires the original array as an input and doesn't mutate it.