Implementing Linked List in Java using Array

In this program, you'll learn to implement Linked List in Java using Array Linked lists are among the simplest and most common data structures. They can be used to implement several other common abstract data types, including stacks, queues, associative arrays, andsymbolic expressions, though it is not uncommon to implement the other data structures directly without using a list as the basis of implementation.

The principal benefit of a linked list over a conventional array is that the list elements can easily be inserted or removed without reallocation or reorganization of the entire structure because the data items need not be stored contiguously in memory or on disk. Linked lists allow insertion and removal of nodes at any point in the list, and can do so with a constant number of operations if the link previous to the link being added or removed is maintained during list traversal.

On the other hand, simple linked lists by themselves do not allow random access to the data, or any form of efficient indexing. Thus, many basic operations — such as obtaining the last node of the list (assuming that the last node is not maintained as separate node reference in the list structure), or finding a node that contains a given datum, or locating the place where a new node should be inserted — may require scanning most or all of the list elements.

Operations :

  1. isEmpty() - Returns true if the List is empty ,false other wise.
  2. size() - Give the number of element in the list.
  3. get(theIndex) - Give the element with gives index.
  4. indexOf(theElement) - Determines the index of a given element.
  5. remove(theIndex) - Removes element with a given index and returns it.add(theIndex,theElement) - Add a given element so that new element has a specified index.

Linear list Interface:

Implementing Linked List in Java using Array

When you run the program, the output will be:

[58, 60, 72, 70, 75]

Previous Post Next Post