
- 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
The addAll(Collection<? extends E> c) method is used to append all of the elements in the specified collection to the end of the list.The order will be same as they are returned by the specified collection's Iterator. This method should not be called at the same time while modifying the collection.This will cause undefined behavior and incorrect result.
Declaration
Following is the declaration for java.util.Vector.addAll() method
public boolean addAll(Collection<? extends E> c)
Parameters
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
Example
The following example shows the usage of java.util.Vector.addAll(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 secondvec with firstvec vector firstvec.addAll(secondvec); // let us print all the elements available in vector firstvec 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 appended with first list content.
Added numbers are :- Number = 1 Number = 2 Number = 3 Number = 4 Number = 5 Number = 6 Number = 7 Number = 8