Java comes with many Data Structures of which very often used is ArrayList. The advantage of ArrayList is it accepts duplicates and the methods are not synchronized. For this reason, the execution of Java array list is faster. The elements can be added or retrieved very fast.
Following is a simple example on Java array list where elements are added and retrieved.
public class ArrayListDemo
public static void main(String args)
ArrayList al1 = new ArrayList();
// printing elements
System.out.println("\nPrinting array list elements with Iterator interface");
Iterator it = al1.iterator();
ArrayList object al1 is added with different types of elements with add() method. The iterator() method returns an object of Iterator interface. Iterator object it includes all the elements of al1. hasNext() method iterates all the elements and next() method prints each element.