ArrayList in Java
ArrayList in Java
Illustration:
Java
// Java program to demonstrate the
// working of ArrayList in Java
import java.io.*;
import java.util.*;
class ArrayListExample {
public static void main(String[] args)
{
// Size of the
// ArrayList
int n = 5;
// Printing elements
System.out.println(arrli);
Since ArrayList is a dynamic array and we do not have to specify the size
while creating it, the size of the array automatically increases when we
dynamically add and remove items. Though the actual library
implementation may be more complex, the following is a very basic idea
explaining the working of the array when the array becomes full and if we try
to add an item: