Introduction
The List interface in Java defines an ordered collection of elements. The ArrayList is a resizable array implementation of the List interface that is part of the java.util package. ArrayList grows and shrinks dynamically on the addition and removal of elements, respectively. It also inherits the AbstractList class and executes the RandomAccess, List, and Serializable interfaces. It is comparatively slower than built-in arrays but can be beneficial in lots of array manipulation programs.

In this article, we will see how to add date in ArrayList Java with the help of different methods and examples. So, Let’s get started!
Methods to Add Date in ArrayList Java
There are various methods using which we can add a date in the arraylist. Some of the methods are as follows:
Using the add() function
This is the easiest way to add a date to an ArrayList. In this method, we use the add() function, which is given by the ArrayList class, to add a date to an ArrayList.
Code
Output

Explanation
In the above example, we created an ArrayList of Object DateList, and then we used the add() function to add two dates to it. The first date provided is the current date and time, which is accessed by executing the DateList Class’s no-argument constructor. The second date provided is the date two days before the current date and time, which can be calculated by subtracting 48 hours from the current time.
Using Set() Function
Code
Output

Explanation
In the above code, we have added two dates to our ArrayList, five and seven days before the current date and time. Then, the set() function is used to change the second date with a new date that is ten days before the current date and time.
Using addAll() function
In this method, we will use the addAll() function to add date in ArrayList. This function adds numerous entries to an ArrayList at once. This function can be used when we want to add numerous dates to an ArrayList.
Code
Output

Explanation
In the above example, we started by making a List of Date objects with two dates, four and six days before the current date and time. We then used the addAll() function to add these dates to our ArrayList.
Using the add() method with a specified object type
This method uses the ArrayList to store items of various sorts. We can add a Date Object and a string object to the ArrayList using this method. We define the Object as the object type in ArrayList declaration to enable storing of objects of multiple types.
Code
Output

Explanation
In the above code, we have added Date objects and a String object to the ArrayList. Also, along with the date, we have printed the string. We have created a List of Date Objects with two dates, two and three days before the current date and time.
Using the add() method with a given index
In this method, we have used the add() method to put a new Date Object in the ArrayList at a specified index. In the following example, we have entered the date four days ago at index one, relocating the previous dates to the right.
Code
Output
