Java 8 Collection Framework: List
2 min read
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:-
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
Did you find this article valuable?
Support Atharva Siddhabhatti by becoming a sponsor. Any amount is appreciated!