java.util.Vector.addAll(Collection C): This method is used to append all of the elements from the collection passed as a parameter to this function to the end of a vector keeping in mind the order of return by the collection’s iterator.
Syntax:
boolean addAll(Collection C)
Parameters: The method accepts a mandatory parameter C which is a collection of ArrayList. It is the collection whose elements are needed to be appended at the end of the vector.
Return Value: The method returns True if at least one action of append is performed, else False.
Below program illustrate the Java.util.Vector.addAll() method:
Java
import java.util.*;
import java.util.ArrayList;
public class GFG {
public static void main(String args[])
{
Vector<String> vt = new Vector<String>();
vt.add("Geeks");
vt.add(" for ");
vt.add("Geeks");
vt.add(" 10 ");
vt.add(" 20 ");
Collection<String> c = new ArrayList<String>();
c.add("A");
c.add("Computer");
c.add("Portal");
c.add(" for ");
c.add("Geeks");
System.out.println("The Vector is: " + vt);
vt.addAll(c);
System.out.println("The new vector is: " + vt);
}
}
|
Output:
The Vector is: [Geeks, for, Geeks, 10, 20]
The new vector is: [Geeks, for, Geeks, 10, 20, A, Computer, Portal, for, Geeks]
Time complexity: O(n + m). // O(n) is the number of elements in the vector and O(m) is for the collection of elements.
Auxiliary Space: O(n+m).
java.util.Vector.addAll(int index, Collection C): This method is used to append all of the elements from the collection passed as a parameter to this function at a specific index or position of a vector.
Syntax:
boolean addAll(int index, Collection C)
- Parameters: This function accepts two parameters as shown in the above syntax and are described below.
- index: This parameter is of integer datatype and specifies the position in the vector starting from where the elements from the container will be inserted.
- C: It is a collection of ArrayList. It is the collection whose elements are needed to be appended.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!