Java Vector addAll() Method
The addAll() Java Vector class method inserts all of the elements in the specified collection to the end of the vector which is in use. The order of the elements will be the same as they are returned by the specified collection's iterator. There is two different types of Java addAll() method which can be differentiated depending on its parameter. These are:
addAll(Collection<? extends E> c) Method:
This method is used to append all of the elements in the specified collection to the end of this Vector.
addAll(int index, Collection<? extends E> c) Method:
This method is used to insert all of the elements in the specified collection into the vector which is in use at the specified position.
Following is the declaration of addAll() method:
The addAll() method returns true if this Vector changed as a result of the call.
NullPointerException- This method has thrown an exception if the specified collection is null.
IndexOutOfBoundsException- This method has thrown an exception if the index of an array is out of range i.e. (index < 0 || index > size()).
Java 1.2 and above
Example 1:Test it Now
List of first arrayList: [1, 2, 3] List of second arrayList: [4, 5, 6, 7] Final arrayList: [1, 2, 3, 4, 5, 6, 7]
Example 2:Test it Now
Final vector list: [A, B, C, D, E, F, G, H]
Example 3:Test it Now
Final vector list: [Java, Android, Python, PHP]
Example 4:Test it Now
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 3 at java.base/java.util.Vector.addAll(Vector.java:1064) at myPackage.VectorAddAllExample4.main(VectorAddAllExample4.java:16)