Java Program to Add Elements of a Vector to Other Vector Collection at the Specified Position

You are currently viewing Java Program to Add Elements of a Vector to Other Vector Collection at the Specified Position

Java program to add elements of a vector to other vector collection at the specified position

// Java program to add elements of a vector to other 
// vector collection at the specified position

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Vector vec1 = new Vector();
    Vector vec2 = new Vector();

    vec1.add(10);
    vec1.add(20.5);
    vec1.add(true);
    vec1.add("Hello World");

    vec2.add("A");
    vec2.add("B");
    vec2.add("C");
    vec2.add("D");

    System.out.println("Vector Vec1 : " + vec1);
    System.out.println("Vector Vec2 : " + vec2);

    vec1.addAll(2, vec2);

    System.out.println("\nVector Vec1 : " + vec1);
    System.out.println("Vector Vec2 : " + vec2);
  }
}

Output

Vector Vec1 : [10, 20.5, true, Hello World]
Vector Vec2 : [A, B, C, D]

Vector Vec1 : [10, 20.5, A, B, C, D, true, Hello World]
Vector Vec2 : [A, B, C, D]

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply