How to use ArrayUtils for array of objects, it doesn’t delete the content of an array

Change this

ArrayUtils.remove(listItems, i);

to

listItems = ArrayUtils.remove(listItems, i);

As you can see in the JavaDoc, the method does not change the argument listItems, rather it returns a new array with the remaining elements.

Edit

You also need to change your deletion method to

public static ItemTracker[] deleteItem(ItemTracker[] listItems) {
    //..
}

So you could return the new array with the remaining elements.

Leave a Comment