How to Declare an ArrayList with Values in Java? Last Updated : 01 Feb, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report ArrayList is simply known as a resizable array. Declaring an ArrayList with values is a basic task that involves the initialization of a list with specific elements. It is said to be dynamic as the size of it can be changed. Proceeding with the declaration of ArrayList, we have to be aware of the concepts of Arrays and Lists in Java programming. In this article, we will learn to declare an ArrayList with values in Java. Program to declare an ArrayList with ValuesIt is the easiest and most direct method to add values while declaration. There is a basic way to declare an ArrayList with values is by Adding elements one by one by using the add() method. Syntax:ArrayList<Integer> arrayList = new ArrayList<>();arrayList.add(1);arrayList.add(2);Below is the implementation of Declare an ArrayList with Values in Java: Java //Java program to declare an ArrayList with values //importing util package to use the methods import java.util.*; public class GFG { public static void main(String[] args) { // Declare and initialize ArrayList using Arrays.asList ArrayList<Integer> arrayList = new ArrayList<>(); //Adding Values to the ArrayList arrayList.add(5); arrayList.add(1); arrayList.add(2); arrayList.add(4); // Print ArrayList System.out.println("ArrayList: " + arrayList); } } OutputArrayList: [5, 1, 2, 4] Explanation of the above Program:In the above example, from the java.util package we have imported the ArrayList class.Then, we have declared an ArrayList with the name arrayList and it stores the integer objects.After that we have used the add() method to add elements to ArrayList.At last, it prints all the values to an ArrayList. Comment More infoAdvertise with us Next Article How to Add Element in Java ArrayList? D digitalvasanth Follow Improve Article Tags : Java Java Programs Java-ArrayList Practice Tags : Java Similar Reads How to Add Element in Java ArrayList? Java ArrayList class uses a dynamic array for storing the elements. It is like an array, but there is no size limit. We can add or remove elements anytime. So, it is much more flexible than the traditional array. Element can be added in Java ArrayList using add() method of java.util.ArrayList class. 2 min read How Objects Can an ArrayList Hold in Java? ArrayList is a part of the collection framework and is present in java.util package. It provides us with dynamic arrays in Java just as Vector in C++. Though, it may be slower than standard arrays but can be helpful in programs where lots of manipulation in the array is needed. In order to understan 3 min read How to Serialize ArrayList in Java? ArrayList is a class under the collections framework of java. It is present in java.util package. An ArrayList is a re-sizable array in java i.e., unlike an array, the size of an ArrayList can be modified dynamically according to our requirement. Also, the ArrayList class provides many useful method 2 min read Convert ArrayList to Vector in Java There are several ways to convert ArrayList to Vector. We can use a vector constructor for converting ArrayList to vector. We can read ArrayList elements one by one and add them in vector. Approach 1: (Using Vector Constructor) Create an ArrayList.Add elements in ArrayList.Create a vector and pass t 3 min read How to Convert an ArrayList into a JSON String in Java? In Java, an ArrayList is a resizable array implementation of the List interface. It implements the List interface and is the most commonly used implementation of List. In this article, we will learn how to convert an ArrayList into a JSON string in Java. Steps to convert an ArrayList into a JSON str 2 min read Which Data Type Cannot be Stored in Java ArrayList? The ArrayList class implements a growable array of objects. ArrayList cannot hold primitive data types such as int, double, char, and long. With the introduction to wrapped class in java that was created to hold primitive data values. Objects of these types hold one value of their corresponding prim 4 min read Like