The add(E ele) method of AbstractList class in Java is used to insert the specified element to the end of the current list.
public boolean add(E ele)
Where E is the type of element maintained
by this AbstractList collection.
Parameter: This method accepts a single parameter ele which represents the element to be inserted at the end of this list.
Return Value: The function returns a boolean value True if the element is successfully inserted in the List otherwise it returns False.
- UnsupportedOperationException – It throws this exception if the add() operation is not supported by this list.
- ClassCastException – It throws this exception if the class of the specified element prevents it from being added to this list.
- NullPointerException – It throws this exception if the specified element is null and this list does not permit null elements.
- IllegalArgumentException – It throws this exception if some property of this element prevents it from being added to this list.
Below programs illustrate the AbstractList.add(E ele) method:
Number = 15 Number = 20 Number = 25
Geeks For Geeks
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.