0% found this document useful (0 votes)
27 views8 pages

List Interface

The Java Collection Framework includes the List interface, which is implemented by classes such as ArrayList, LinkedList, Vector, and Stack. Lists are ordered collections that allow duplicate values and support various operations like adding, removing, and accessing elements by index. Additionally, methods for searching elements and obtaining sublists based on index ranges are provided.

Uploaded by

abhimanyu thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views8 pages

List Interface

The Java Collection Framework includes the List interface, which is implemented by classes such as ArrayList, LinkedList, Vector, and Stack. Lists are ordered collections that allow duplicate values and support various operations like adding, removing, and accessing elements by index. Additionally, methods for searching elements and obtaining sublists based on index ranges are provided.

Uploaded by

abhimanyu thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Java

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.

•int indexOf(Object o): This method returns first occurrence of given


element or -1 if element is not present in list.
•int lastIndexOf(Object o): This method returns the last occurrence of
given element or -1 if element is not present in list.
Range View in List:
• List Interface provides method to get List view
of the portion of given List between two indices.

List subList(int fromIndex,int toIndex):This method returns List view


of specified List between fromIndex(inclusive) and toIndex(exclusive).

You might also like