
- Java.util Package Classes
- Java.util - Home
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util Package Extras
- Java.util - Interfaces
- Java.util - Exceptions
- Java.util - Enumerations
- Java.util Useful Resources
- Java.util - Useful Resources
- Java.util - Discussion
java.util.Vector.addAll() Method
Description
This addAll(int index,Collection<? extends E> c) method is another variant of the previous addAll() method. It inserts all of the elements in the specified collection into this list. The insertion starts at the specified position/index and shifts the element currently at that position (if any).The corresponding indices are also increased to shift subsequent elements to the right.The new elements will appear in the list in the same order as they are returned by the specified collection's iterator.
Declaration
Following is the declaration for java.util.Vector.addAll() method
public boolean addAll(int index,Collection<? extends E> c)
Parameters
index − This is the index/position where the first element from the specified collection will be inserted.
c − This is the collection containing elements to be added to this list .
Return Value
The return type is true if this list is changed as a result of the call.
Exception
NullPointerException − The method call will throw this exception if the specified collection is null.
IndexOutOfBoundsException − This exception will be thrown if the accessed index/position is out of range (index < 0 || index > size()).
Example
The following example shows the usage of java.util.Vector.addAll(int index,Collection<? extends E> c) method.
package com.tutorialspoint; import java.util.Vector; public class VectorDemo { public static void main(String[] args) { // create two empty Vectors firstvec and secondvec Vector<Integer> firstvec = new Vector<Integer>(4); Vector<Integer> secondvec = new Vector<Integer>(4); // use add() method to add elements in the secondvec vector secondvec.add(5); secondvec.add(6); secondvec.add(7); secondvec.add(8); // use add() method to add elements in the firstvec vector firstvec.add(1); firstvec.add(2); firstvec.add(3); firstvec.add(4); /** use addAll() method to add elements of the 2nd vector at 1st element position of the first vector */ firstvec.addAll(1,secondvec); // let us print all the elements available in vector System.out.println("Added numbers are :- "); for (Integer number : firstvec) { System.out.println("Number = " + number); } } }
Let us compile and run the above program, this will produce the following result.Check the second list contents are inserted at the 1st element position of the first list content.
Added numbers are :- Number = 1 Number = 5 Number = 6 Number = 7 Number = 8 Number = 2 Number = 3 Number = 4