What does the method removeElementAt(int index) do in java?

Java 8Object Oriented ProgrammingProgramming

The removeElementAt(int index) method is used to delete the component at the specified index. Each component in this vector with an index greater or equal to the specified index is shifted downward to have an index one smaller than the value it had previously and the size of this vector is decreased by 1.

Example

public class VectorDemo {
   public static void main(String[] args) {
      Vector<Integer> vec = new Vector<Integer>(4);
      vec.add(4);
      vec.add(3);
      vec.add(2);
      vec.add(1);
      System.out.println("Remove element at index 2");
      vec.removeElementAt(2);
      System.out.println("Added numbers are :- ");

      for (Integer number : vec) {
         System.out.println("Number = " + number);
      }
   }
}

Output

Remove element at index 2
Added numbers are :-
Number = 4
Number = 3
Number = 1
raja
Published on 08-Feb-2018 09:02:08
Advertisements