Wednesday, December 20, 2017

List



List is child interface of collection. If we want to represent a group of individual objects as a single entity where duplicates are not allowed in the insertion order , insertion order must be preserved then we should go for List.


We can preserve insertion order by the index and we can differentiate to duplicate objects by using index.

So index will play very important role in a List.

Below is the example:

B C D E A
0 1 2 3 4 5    INDEX

List interface defines the following specific methods.

1. void add(int index,object o)
2. Boolean addAll(int index, Collection C)
3. object get(int index) 
4. object set(int index, object value)
5. void remove(int index, object o)





List is implemented by the below classes.

1. ArrayList
2. LinkedList
3. Vector 
 4. Stack