- 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
How to concatenate lists in java?
The addAll(Collection<? extends E> c) method of the class java.util.ArrayList appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's Iterator. Using this method you can concatenate two lists.
Example:
import java.util.ArrayList; public class Sample { public static void main(String[] args) { ArrayList<String> list = new ArrayList<String>(); list.add("JavaFx"); list.add("Java"); list.add("WebGL"); list.add("OpenCV"); System.out.println(list); ArrayList<String> newList = new ArrayList<String>(); list.add("HBase"); list.add("Neo4j"); list.add("MangoDB"); list.add("Cassandra"); list.addAll(newList); System.out.println(list); } }
Output:
[JavaFx, Java, WebGL, OpenCV] [JavaFx, Java, WebGL, OpenCV, HBase, Neo4j, MangoDB, Cassandra]
- Related Articles
- How to join or concatenate two lists in C#?
- How to append list to second list (concatenate lists) in Python?
- Concatenate two lists element-wise in Python
- Python program to concatenate every elements across lists
- How to concatenate two arrays in java?
- How to concatenate byte array in java?
- Is there a MongoDB query to concatenate deep sub-lists?
- How to concatenate two strings using Java?
- Java Program to Concatenate String.
- Different ways to concatenate Strings in Java
- Concatenate null to a string in Java
- How can I concatenate two arrays in java
- Concatenate Multiple Strings in Java.
- How to create an array of linked lists in java?
- Java Program to Concatenate Two Arrays

Advertisements