DEV Community

aryan
aryan

Posted on

2 1

How to initialize ArrayList in Java?

The Java ArrayList can be initialized in number of ways depending on the requirement. In this tutorial, we will learn to initialize ArrayList based on some frequently seen usecases.

See original article: https://www.java8net.com/2020/03/initialize-arraylist-in-java.html

How to initialize ArrayList in Java - using Arrays.asList() method?

import java.util.ArrayList;
import java.util.Arrays;

public class ArrayListExample {
public static void main(String[] args) {
ArrayList list = new ArrayList<>(
Arrays.asList("A", "B", "C", "D", "E"));
System.out.println("ArrayList : " + list);
}
}

Related Posts:
https://www.java8net.com/2020/03/java-arraylist-common-program-examples.html
https://www.java8net.com/2020/03/arraylist-to-hashmap-in-java.html
https://www.java8net.com/2020/03/how-to-remove-duplicates-from-arraylist-in-java.html
https://www.java8net.com/2020/03/iterate-arraylist-in-java.html
https://www.java8net.com/2020/03/java-sublist-from-arraylist.html

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

DEV shines when you're signed in, unlocking a customized experience with features like dark mode!

Okay