deleting elements from a vector

Hi, I have the following test code, where I add a product to a vector. A product consists of 6 vector elements hence the for loop...

for(int y=0; y<itemsOrdered.size(); y+=6)

However whenever I try and remove an item from this vector I keep getting

'Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException:

3 >= 3' Note I am using an IDE to test this code, thats why the servlet has a main method, as its not really a servlet at the moment, but will be later.

Vector itemsOrdered =new Vector();

itemsOrdered.add(0,"2000");

itemsOrdered.add(1,"x45");

itemsOrdered.add(2,"sony");

itemsOrdered.add(3,"audio");

itemsOrdered.add(4,"nice cd");

itemsOrdered.add(5,"?5");

System.out.println("itemsOrdered size is when ADDED! " + itemsOrdered.size());

for(int y=0; y<itemsOrdered.size(); y+=6){

for(int g=0; g><6; g++){

String anItemLine = (String)itemsOrdered.get(g);

System.out.println("item line is " + anItemLine);

itemsOrdered.removeElementAt(g);

}

}

Can anyone help?

[1672 byte] By [pete_484a] at [2007-11-26 15:37:04]
# 1
I am quite sure you want to look at the way you increment your for loops..And why not use foreach with generics.MeTitus
Me_Titusa at 2007-7-8 21:54:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...