0% found this document useful (0 votes)
11 views

Array List

The document provides an overview of the ArrayList class in Java, which supports dynamic arrays that can grow as needed. It includes examples demonstrating how to create an ArrayList, add elements, traverse the list using an iterator, access, and modify elements. The content is aimed at students of the Amity School of Engineering & Technology (CSE).

Uploaded by

mdivyansh866
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Array List

The document provides an overview of the ArrayList class in Java, which supports dynamic arrays that can grow as needed. It includes examples demonstrating how to create an ArrayList, add elements, traverse the list using an iterator, access, and modify elements. The content is aimed at students of the Amity School of Engineering & Technology (CSE).

Uploaded by

mdivyansh866
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Amity School of Engineering & Technology (CSE)

ArrayList
Amity School of Engineering & Technology (CSE)

Introduction

The ArrayList class


ArrayList supports
extends
dynamic arrays
AbstractList and
that can grow as
implements the List
needed.
interface.

Array lists are


created with an
initial size. When
When objects are
this size is
removed, the array
exceeded, the
may be shrunk.
collection is
automatically
enlarged.
Amity School of Engineering & Technology (CSE)

Constructors
Amity School of Engineering & Technology (CSE)

Example 1
import java.util.*;
public class ArrayListDemo{
public static void main(String args[]){
ArrayList<String> list=new ArrayList<String>();//Creating arraylist
list.add(“Java");//Adding object in arraylist
list.add(“C++");
list.add(“C");
list.add(“Python");
//Printing the arraylist object
System.out.println(list);
}
}
Amity School of Engineering & Technology (CSE)

Example 2
import java.util.*;
public class ArrayListDemo{
public static void main(String args[]){
ArrayList<String> list=new ArrayList<String>();//Creating arraylist
list.add(“Java");//Adding object in arraylist
list.add(“C++");
list.add(“C");
list.add(“Python");
//Traversing list through Iterator
Iterator itr=list.iterator(); //getting the Iterator
while(itr.hasNext()){ //check if iterator has the elements
System.out.println(itr.next());//printing the element and move to next
}
}
}
Amity School of Engineering & Technology (CSE)

Example 3
//accessing the element
System.out.println("Returning element: "+list.get(1));//it will return the 2nd
element, because index starts from 0

//changing the element


list.set(1,“C#");

//Traversing list
for(String prog:list)
System.out.println(prog);

You might also like