How do i remove an element from an Array in java without getting: java.lang.ArrayIndexOutOfBoundsException?

I want to remove an index from and array and have tried to do so by copying over all the elements except the one that I want to remove in to a new array, however my solution gets ArrayIndexOutOfBoundsException, what should I do to solve this?

public void removeItem(Item item) {

        Item[] ownedItemCopy  = new Item [ownedItem.length - 1 ];
            for (int i = 0; i < ownedItem.length; i++) { 
                if(!ownedItem[i].equals(item)) {
                int j=i;    

Read more here:

Content Attribution

This content was originally published by tewi at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: