• 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 SM

    Leave a Comment

    Your email address will not be published. Required fields are marked *

    Share on facebook
    Share on google
    Share on twitter
    Share on linkedin
    Share on whatsapp

    Recent Posts:

    Scroll to Top
    API Testing eBook

    DOWNLOAD FOR FREE