Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves. Alan Kay


Language Java | Level Intermediate | Category Java collections framework (JCF) | 2015-07-22 19:48:18



ArrayList is a resizable array implementation of the ordered collection.


ArrayList is index based and permits null.
It does not support synchronization which cannot be accessed using multiple threads.
It can throw ConcurrentModificationException.
The fail-fast behavior of iterators should be used only to detect bugs.
It takes more memory to store the element and link to the next node compare than Array List.

source Code

package com.careerdrill.collections.list;

import java.util.ArrayList;
import java.util.List;

public class ArrayListUse {

	public static void main(String[] args) {

	      List< Integer > al = new ArrayList< Integer >();
	      System.out.println("Initial size of Array List: " + al.size());

	      al.add(1, 77);
	      System.out.println("Size of Array List after additions: " + al.size());
	      System.out.println("Elements from Array List : " + al.toString());

	      System.out.println("Contents of Array List: " + al);

	      al.remove(new Integer(77));
	      System.out.println("Size of Array List after deletions: " + al.size());
	      System.out.println("Contents of Array List: " + al);




Initial size of Array List: 0
Size of Array List after additions: 7
Elements from Array List: [11, 77, 22, 33, 44, 55, 66]
Contents of Array List: [11, 77, 22, 33, 44, 55, 66]
Size of Array List after deletions: 5
Contents of Array List: [11, 22, 44, 55, 66]


LinkedList ArrayList
Linked list search operation is slower than array list. ArrayList search operation is pretty fast compared to the LinkedList.
LinkedList element addition and deletion is faster compared to ArrayList. Array List takes more time for inserting and deleting the elements.
LinkedList has more memory overhead than ArrayList. ArrayList has less memory overhead compare than LinkedList.
Internally uses dynamic array. Internally uses doubly linked list.
Linked list uses links and no need adjust index. ArrayList need to adjust the indexes according to deletion or insertion.

When to use

When you want more search operation rather than insertion and deletion middle of the list, you can use array list.


Please login to add comments.