Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
How to Add All Items From a Collection to an ArrayList in Java?
Next article icon

How to Add All Items From a Collection to an ArrayList in Java?

Last Updated : 13 Feb, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In Java, to add all items from a collection to an ArrayList we use the addAll() method. This method appends all elements from a specified collection to the end of the list.

Approach:

  1. Get the Collection whose items are to be added to the ArrayList.
  2. Create an ArrayList
  3. Add all the items of Collection into this ArrayList using ArrayList.addAll() method.
  4. ArrayList with all the items of Collections have been created.

Example: This example demonstrates how to add all elements from a collection to an ArrayList using the addAll() method.

Java
// Java Program to add all items // from a collection to an ArrayList // using addAll() method import java.util.ArrayList; import java.util.Collection;  public class Geeks {     public static void main(String[] args) {                  // Create a Collection         Collection<String> c = new ArrayList<>();         c.add("A");         c.add("B");         c.add("C");          // Create an ArrayList         ArrayList<String> al = new ArrayList<>();          // Add all items from the collection          // to the ArrayList         al.addAll(c);          // Print the ArrayList         System.out.println(al);     } } 

Output
[A, B, C] 

Next Article
How to Add All Items From a Collection to an ArrayList in Java?

C

code_r
Improve
Article Tags :
  • Java
  • Java-Collections
  • Java-ArrayList
Practice Tags :
  • Java
  • Java-Collections

Similar Reads

    How to add selected items from a collection to an ArrayList in Java?
    Given a Collection with some values, the task is to add selected the items of this Collection to an ArrayList in Java. Examples: Input: Collection = [1, 2, 3], condition = (item != 2) Output: ArrayList = [1, 3] Input: Collection = [GFG, Geek, GeeksForGeeks], condition = (item != GFG) Output: ArrayLi
    2 min read
    How to Convert HashMap to ArrayList in Java?
    In Java a HashMap is a collection that stores key-value pairs on the other hand, an ArrayList is a collection that stores dynamic arrays. There are some scenarios where we need to convert a HashMap into an ArrayList such as:Extracting only the keys or values in the list form.Converting key-value pai
    2 min read
    Conversion of Array To ArrayList in Java
    Following methods can be used for converting Array To ArrayList: Method 1: Using Arrays.asList() method Syntax: public static List asList(T... a) // Returns a fixed-size List as of size of given array. // Element Type of List is of same as type of array element type. // It returns an List containing
    5 min read
    How to Get ArrayList from Stream in Java 8?
    Given a Stream, the task is to convert this Stream into ArrayList in Java 8. Examples:Input: Stream: [1, 2, 3, 4, 5]Output: ArrayList: [1, 2, 3, 4, 5]Input: Stream: ['G', 'e', 'e', 'k', 's']Output: ArrayList: ['G', 'e', 'e', 'k', 's']1. Using Collectors.toList() method: Approach:Get the Stream to be
    2 min read
    Array to ArrayList Conversion in Java
    In Java, arrays are fixed-sized, whereas ArrayLists are part of the Java collection Framework and are dynamic in nature. Converting an array to an ArrayList is a very common task and there are several ways to achieve it.Methods to Convert Array to an ArrayList1. Using add() Method to Manually add th
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences