java.util.Vector.addAll(Collection<? extends E> c) 方法示例


java.util.Vector.addAll(Collection<? extends E> c) 方法示例

package com.codingdict;

import java.util.Vector;

public class VectorDemo {
   public static void main(String[] args) {

      // create two empty Vectors firstvec and secondvec      
      Vector<Integer> firstvec = new Vector<Integer>(4);      
      Vector<Integer> secondvec = new Vector<Integer>(4);

      // use add() method to add elements in the secondvec vector
      secondvec.add(5);
      secondvec.add(6);
      secondvec.add(7);
      secondvec.add(8);

      // use add() method to add elements in the firstvec vector
      firstvec.add(1);
      firstvec.add(2);
      firstvec.add(3);
      firstvec.add(4);

      // use addAll() method to add secondvec with firstvec vector
      firstvec.addAll(secondvec);

      // let us print all the elements available in vector firstvec vector
      System.out.println("Added numbers are :- ");

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