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

原文链接:How to initialize ArrayList in Java?

© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容