DEV Community

Cover image for Java 8 Collection Framework: List
Atharva Siddhabhatti
Atharva Siddhabhatti

Posted on

Java 8 Collection Framework: List

The List is one of the interfaces of the collection which extends the collection and declares the behavior that stores a group of elements. List is kind of an array which stores the elements and which can be inserted of accessed by their index position in the list. The index starts from 0.

interface List
E is the type of object which the list will hold. List also has its own methods defined. Some methods can throw different kind of Exceptions. If we try to save null object in the list then NullPointerException Will be thrown as null elements are not allowed in the list.

There are Many methods which are supported by the list:-

List Methods

The void add(int index,E) adds the element at a specified index position in the list.
boolean addAll(int index,Collection) adds the group if element starting from the given index position. Returns true if the list is changed otherwise will return false.

To get the object stored at a particular index the get(index) method is used.
The int indexOf(Object obj) returns the index of that particular object.
For all versions, null elements are not allowed. In all cases, the List implementation is unspecified.

Click Run below code to see some of the methods running:-

In the next blog we will see Set Interface.

Reference Links of the series:-
1) Collection Framework Introduction

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay