- 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 code to illustrate boolean addAll()importjava.util.*;importjava.util.ArrayList;publicclassGFG {publicstaticvoidmain(String args[]){// Creating an empty VectorVector<String> vt =newVector<String>();// Use add() method to add elements in the Vectorvt.add("Geeks");vt.add("for");vt.add("Geeks");vt.add("10");vt.add("20");// A collection is createdCollection<String> c =newArrayList<String>();c.add("A");c.add("Computer");c.add("Portal");c.add("for");c.add("Geeks");// Displaying the VectorSystem.out.println("The Vector is: "+ vt);// Appending the collection to the vectorvt.addAll(c);// Clearing the vector using clear() and displayingSystem.out.println("The new vector is: "+ vt);}}chevron_rightfilter_noneOutput:
The Vector is: [Geeks, for, Geeks, 10, 20] The new vector is: [Geeks, for, Geeks, 10, 20, A, Computer, Portal, for, Geeks]
- 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.
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 code to illustrate boolean addAll()importjava.util.*;importjava.util.ArrayList;publicclassGFG {publicstaticvoidmain(String args[]){// Creating an empty VectorVector<String> vt =newVector<String>();// Use add() method to add elements in the Vectorvt.add("Geeks");vt.add("for");vt.add("Geeks");vt.add("10");vt.add("20");// A collection is createdCollection<String> c =newArrayList<String>();c.add("A");c.add("Computer");c.add("Portal");c.add("for");c.add("Geeks");// Displaying the VectorSystem.out.println("The Vector is: "+ vt);// Appending the collection to the vectorvt.addAll(1, c);// Clearing the vector using clear() and displayingSystem.out.println("The new vector is: "+ vt);}}chevron_rightfilter_noneOutput:The Vector is: [Geeks, for, Geeks, 10, 20] The new vector is: [Geeks, A, Computer, Portal, for, Geeks, for, Geeks, 10, 20]
Recommended Posts:
- ArrayDeque addAll() method in Java
- LinkedList addAll() Method in Java
- ConcurrentLinkedQueue addAll() method in Java
- TreeSet addAll() Method in Java
- Collection addAll() method in Java with Examples
- AbstractList addAll() method in Java with Examples
- Stack addAll(Collection) method in Java with Example
- Collections addAll() method in Java with Examples
- AbstractCollection addAll() Method in Java with Examples
- Stack addAll(int, Collection) method in Java with Example
- AbstractQueue addAll() method in Java with examples
- ConcurrentLinkedDeque addAll() method in Java with Examples
- AbstractSequentialList addAll() Method in Java with Examples
- Java.util.ArrayList.addall() method in Java
- Vector contains() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



