The Wayback Machine - https://web.archive.org/web/20240618020337/https://www.geeksforgeeks.org/vector-addall-method-in-java/
Open In App

Vector addAll() Method in Java

Last Updated : 24 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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




// Java code to illustrate boolean addAll()
import java.util.*;
import java.util.ArrayList;
 
public class GFG {
    public static void main(String args[])
    {
 
        // Creating an empty Vector
        Vector<String> vt = new Vector<String>();
 
        // Use add() method to add elements in the Vector
        vt.add("Geeks");
        vt.add("for");
        vt.add("Geeks");
        vt.add("10");
        vt.add("20");
 
        // A collection is created
        Collection<String> c = new ArrayList<String>();
        c.add("A");
        c.add("Computer");
        c.add("Portal");
        c.add("for");
        c.add("Geeks");
 
        // Displaying the Vector
        System.out.println("The Vector is: " + vt);
 
        // Appending the collection to the vector
        vt.addAll(c);
 
        // Clearing the vector using clear() and displaying
        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.


Previous Article
Next Article

Similar Reads

Java.util.ArrayList.addall() method in Java
Below are the addAll() methods of ArrayList in Java: boolean addAll(Collection c) : This method appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's Iterator. The behavior of this operation is undefined if the specified collection is modified while the ope
4 min read
LinkedList addAll() Method in Java
java.util.LinkedList.addAll(Collection C): This method is used to append all of the elements from the collection passed as parameter to this function to the end of a list keeping in mind the order of return by the collections iterator. Syntax: boolean addAll(Collection C) Parameters: The parameter C is a collection of ArrayList. It is the collectio
3 min read
TreeSet addAll() Method in Java
The java.util.TreeSet.addAll(Collection C) method is used to append all of the elements from the mentioned collection to the existing set. The elements are added randomly without following any specific order. Syntax: boolean addAll(Collection C) Parameters: The parameter C is a collection of any type that is to be added to the tree set. Return Valu
2 min read
ArrayDeque addAll() method in Java
The addAll() method of ArrayDeque is used to insert all the elements of the collection passed as parameter at the end of this ArrayDeque. For adding elements of a collection to ArrayDeque we have to iterate through the collection and add each element in ArrayDeque by using addAll(E e) method. This method works same as we discussed here but with les
4 min read
ConcurrentLinkedQueue addAll() method in Java
The addAll() method of ConcurrentLinkedQueue is used to inserts all the elements of the Collection, passed as parameter to this method, at the end of a ConcurrentLinkedQueue. The insertion of element is in same order as returned by the collections iterator. Syntax: public boolean addAll(Collection&lt;? extends E&gt; c) Parameter: This method takes
4 min read
Collections addAll() method in Java with Examples
The addAll() method of java.util.Collections class is used to add all of the specified elements to the specified collection. Elements to be added may be specified individually or as an array. The behavior of this convenience method is identical to that of c.addAll(Arrays.asList(elements)), but this method is likely to run significantly faster under
3 min read
AbstractList addAll() method in Java with Examples
The addAll() method of java.util.AbstractList class is used to insert all of the elements in the specified collection into this list at the specified position. This shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in this list in the order that th
4 min read
AbstractQueue addAll() method in Java with examples
The addAll(E e) method of AbstractQueue adds all of the elements in the specified collection to this queue. Syntax: public boolean addAll(Collection c) Parameters: This method accepts a mandatory parameter collection containing elements to be added to this queue Returns: The method returns true if this queue changed as a result of the call Exceptio
3 min read
AbstractCollection addAll() Method in Java with Examples
The addAll(Collection C) method of Java AbstractCollection is used to append all of the elements from a mentioned collection to this collection. The elements are added randomly without following any specific order. Syntax: boolean addAll(Collection C) Parameters: The parameter C is a collection of any type that is to be added to the collection. Ret
2 min read
AbstractSequentialList addAll() Method in Java with Examples
The addAll(int index, Collection C) method of AbstractSequentialList 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 abstract sequential list. Syntax: boolean addAll(int index, Collection C) Parameters: This function accepts two parameters as shown in the above sy
2 min read