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
Top comments (0)