List collection tutorial for Java Beginners

Here we will learn about the List interface and different implementation of it in details. List Interface which is in java.util package is a subtype of java.util.Collection Interface.

List Interface Salient Point

  1. It is a part of java.util package.
  2. It is a subtype of java.util.Collection Interface
  3. List is an Ordered Collection. Means elements of List can be accessed in ordered way (By index).
  4. Allows Duplicate values.
  5. Allows NULL values.
  6. List has a special Iterator named ListIterator. It will help traverse list in both directions.
  7. List has full control on where each element is inserted.

Operations available to List Interface

  • Positional Access
  • Search
  • Iteration
  • Range View

Concrete Implementation of List Interface

  • java.util.ArrayList
  • java.util.LinkedList
  • java.util.Vector
  • java.util.Stack

Create List Instance

Adding Element in List

Access an Element

Syntax : E set(int index, E element);

Purpose : Used to return element at specified position

Return : Returns the element at specified position in given list.

Replace an Element

Syntax : E set(int index, E element);

Purpose: Used to replace an element at specified position in List.

Return: Returns the element replaced.

Performance Point

  • List interface have methods to search for an Object. But same should not be used as it will decrease the performance as in some implementation it will use linear search.
  • List can contain another list as an Element but HashCode and Equals will not apply to these lists and hence same should not be used.

1 Comment List collection tutorial for Java Beginners

  1. Michael

    I think there is a typo error in the section: Access an Element
    you said: Syntax : E set(int index, E element);
    Instead of: Syntax: E get(int index,E element);
    thanks

    Reply

Leave A Comment

Your email address will not be published. Required fields are marked *