ArrayList In Java

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

Rajkumar SM is a founder of SoftwareTestingMaterial. He is a certified Software Test Engineer by profession and blogger & youtuber by choice. He has an extensive experience in the field of Software Testing. He writes here about Software Testing which includes both Manual and Automation Testing. He loves to be with his wife and cute little kid 'Freedom'.

Leave a Comment

Share via
Copy link
Powered by Social Snap