The ArrayList class

Let's get started with the ArrayList class, which implements the List interface. Create a new class and name it arrayListexample. We will first look at the methods present in ArrayList, and then we'll discuss the difference between an array and ArrayList.

We start by declaring ArrayList as follows. If you hover over ArrayList in your IDE, you'll see a suggestion telling you to import java.util for ArrayList:

package coreJava;public class arrayListexample {    public static void main(String[] args) {        ArrayList a=new ArrayList();    }}

Once you do this, it'll still show a suggestion for ArrayList, and if you hover over it, it will suggest adding argument types. To remove this suggestion, you can pass an argument type to ArrayList ...

Get Hands-On Automation Testing with Java for Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.