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

Sharing is caring.

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

Like This Post?

We have a lot more where that came from?

We only send really good stuff occasionally, promise.

Rajkumar

Leave a Comment

API Testing eBook

DOWNLOAD FOR FREE