A very simple Vector in Java that produces the output that is somewhat difficult to follow. The code snippet is as show below.
package main;
import java.util.Vector;
final public class Main
{
public static void main(String[] args)
{
Vector<String> r = new Vector<String>();
r.addElement("O");
r.addElement("Y");
r.insertElementAt("A",0);
r.addElement("B");
r.addElement("F");
r.addElement("I");
r.addElement("X");
r.removeElement("F");
r.insertElementAt("G",3);
System.out.println(r);
}
}
The above simple Java code produces the output that is different than it actually appears to be. The actual output the above code produces is surprisingly, [A, O, Y, G, B, I, X]. Actually, it contains 9 elements. The output however, contains only 7 elements. How?
Did you notice that one of them was
removeElement?