import java.util.*; /**** * * This is a very simple example of a 5-element list of integers, declared as * both an ArrayList and a LinkedList. The interesting thing is the picture of * how memory looks inside the data abstractions: *

* *

* This example uses a couple handy utility methods that convert between lists * and arrays -- asList and toArray. These are defined in * the class java.util.Arrays. Check out its javadoc here . * */ public class ArrayListAndLinkedListExample { public static void main(String[] args) { /* Declare and initialize the ArrayList. */ ArrayList al = new ArrayList(Arrays.asList(10,20,30,40.50)); /* Declare and initialize the LinkedList. */ LinkedList ll = new LinkedList(Arrays.asList(10,20,30,40.50)); /* Show that the lists are equal as arrays. */ System.out.println(Arrays.equals(al.toArray(), ll.toArray())); } }