List Concept Simplified In Java

What is a List:

List is the child interface of collection.Collection interface was introduced in java 1.2 version and  List Interface got introduced in the same version.

Inside list interface there are 3 primary classes. They are..
  1. ArrayList-1.2 version
  2. AbstractSequentialList-1.2 Version
  3. Vector-1.0 version (Legacy class)
2.1 LinkedList-1.2 Version
3.1 Stack (1.0 version-legacy class)

When we should use list:

If we want to represent a group of individual objects as a single entity where duplicates are allowed and insertion order preserved then we should go for List interface.
In Java 1.2 version Vector,Stack classes are re engineered to implement List interface.

As we can preserve the insertion order hence index will be generated. We can differentiate duplicate objects by using Index. So Index plays an important role in List.

List Interface is having the following methods:
  • void add(int index,Object o)
  • boolean addAll(int index,Collection c)
  • Object get(int index)
  • Object remove(int index)
  • Object set(int index,Object new)[This method is very interesting, it replaces the element present at specified index with provided object and returns old object] 
  • int indexOf(Object o) [returns the index of first occurrence of o]
  • int lastIndexOf(Object o)
  • ListIterator  listIterator()
List Concept Simplified In Java List Concept Simplified In Java Reviewed by Animesh Chatterjee on July 16, 2013 Rating: 5

No comments:

Powered by Blogger.