ArrayList In Java with Examples

Earlier we have seen Arrays and we found few limitations of Arrays in Java. Size of an Array is fixed.

Using ArrayList we can overcome the size issue. ArrayList is a resizable array.

ArrayList Class implements List interface. ArrayList allows duplicate elements (remember that Set in Java wont allow duplicate values. We will see Set in later sections)

Output:

ArrayList using For loop:

Output:

ArrayList with For Each Loop:

Output:

ArrayList using Iterator:

Output:

Creation of ArrayList with String elements:

Output:

Adding elements at a given index using ArrayList:

Output:

Must Read: Java Tutorial

Get our latest blog posts delivered to your inbox

Subscribe and get popular blog posts about software testing industry.

Rajkumar

Leave a Comment

Share via
Copy link
Powered by Social Snap