List Interface
List Interface
Collection
List
Interface
Java Collection Framework:
List
• Java.util.List is a child interface of Collection
• ArrayList, LinkedList, Vector & Stack are Java
Classes, which implement List Interface.
• List is an ordered collection of objects in which
duplicate values can be stored.
List Interface:
• Creating List Object :
List a = new ArrayList();
List b = new LinkedList();
List c = new Vector();
List d = new Stack();
Operations in List:
• Object Access: List allows add, remove, get and set
operations based on numerical positions of elements in List.
void add(int index,Object O): This method adds given element at specified index.
boolean addAll(int index, Collection c): This method adds all elements from
specified collection to list. First element gets inserted at given index.
Object remove(int index): This method removes an element from the specified
index.
Operations in List:
Object get(int index): This method returns element at the specified index.
Object set(int index, Object new): This method replaces element at given index
with new element.
Search in List:
• List provides methods to search element and
returns its numeric position.