N/APosted on - 09/18/2011
In learning Java there are many places that needs critical thinking. I am in the process of learning the Java and confused about Linked list and array list. Could anyone tell me what are these and clear comparison how these differentiate with each other. Explain with examples if possible.
LinkedList and ArrayList in Java
Array and Linked List has many differences. An array is a container that holds data of one type. When you declare an array of integer, all the content of the array would be an integer. The length of an array is established once it is defined. It has a bound limit. When declaring an array, you need to define the data type first followed by [ ] and then the array name.
And initializing array can be done this way:
int [ ] anArrayOfIntegers = new int ; //create an array of integers with size of 10
Accessing an array is through index, which starts from 0 to size – 1
int  = 12;
int  = 14;
In the other hand, Linked List is dynamic. The size of a Linked List grows when a new object is added and decrease if one is remove. A Linked List can be sort by stack or queue. Its has a head ( points to the beginning of the list) and a tail ( points to the end of the list) which determines where to insert new data.
Stack sort data by last in first out, means the last entry is first in the line and first entry was on the last. Queue is arranged by first in first out which was opposite to the stack. Here is an example of a Linked List implementation: