- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to append all elements of other Collection to ArrayList
Let us first create an ArrayList −
ArrayList<String>arr = new ArrayList<String>(); arr.add("50"); arr.add("100"); arr.add("150"); arr.add("200"); arr.add("250"); arr.add("300");
Now, let’s say we have another Collection as Vector −
Vector<String>vector = new Vector<String>(); vector.add("500"); vector.add("700"); vector.add("800"); vector.add("1000"); Append all the elements from the Vector to ArrayList: arr.addAll(vector);
Example
import java.util.ArrayList; import java.util.Vector; public class Demo { public static void main(String[] args) { ArrayList<String>arr = new ArrayList<String>(); arr.add("50"); arr.add("100"); arr.add("150"); arr.add("200"); arr.add("250"); arr.add("300"); Vector<String>vector = new Vector<String>(); vector.add("500"); vector.add("700"); vector.add("800"); vector.add("1000"); // append arr.addAll(vector); System.out.println("Result after append..."); for (String str: arr) System.out.println(str); } }
Output
Result after append... 50 100 150 200 250 300 500 700 800 1000
- Related Articles
- Append all elements of other Collection to ArrayList in Java
- Java Program to insert all elements of other Collection to specified Index of ArrayList
- Insert all elements of other Collection to Specified Index of Java ArrayList
- Append all elements of another Collection to a Vector in Java
- How to remove all elements of ArrayList in Java?
- Remove all the elements from an ArrayList that are in another Collection in Java
- Copy all elements of ArrayList to an Object Array in Java
- Java Program to Remove duplicate elements from ArrayList
- Java Program to Shuffle the Elements of a Collection
- Java Program to Find Common Elements in Two ArrayList
- Java Program to Compare Elements in a Collection
- Replace All Elements Of ArrayList with with Java Collections
- Reverse order of all elements of ArrayList with Java Collections
- Remove all elements from the ArrayList in Java
- How to copy elements of ArrayList to Java Vector

Advertisements