0

Anyone know how to remove an object at a particular index from an array? Im doing a Noah's Ark project for my class and Im using an Array to hold the abstract animal class and once an animal dies, I have to remove it from the list. However I can't seem to get it right. Any help would be nice :)

6
Contributors
6
Replies
7
Views
12 Years
Discussion Span
Last Post by miri
0

you mean if you had the following:

intArray[0] = 0;
intArray[1] = 1;
intArray[2] = 2;
intArray[3] = 3;
intArray[4] = 4;

and you wish to convert it to:

intArray[0] = 0;
intArray[1] = 1;
intArray[2] = 3;
intArray[3] = 4;

you could use a for loop starting at i=3 and assign intArray = intArray[i+1], until i<intArray.length-1
but that still raises the problem of what do we assign intArray[4] to equal? I would definatly go with a java.util.ArrayList<E> as this is exactly what you seem to be looking for a resizeable array list. With a prebuilt delete method.

0

don't use Vector, it's a legacy class that should have been deprecated years ago.

java.util is a legacy package, how do you figure Vectors should have been deprecated? It is part of the collections framework, they also updated it for java 1.5 to support enumerated types

0

Still using Vectors - because of some things related to threads.
And it is more suitable than others.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.