AbstractList add(E ele) method in Java with Examples Last Updated : 17 Dec, 2018 Comments Improve Suggest changes Like Article Like Report The add(E ele) method of AbstractList class in Java is used to insert the specified element to the end of the current list. Syntax: 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. Exceptions: 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: Program 1: Java // Java code to illustrate add(Object o) import java.io.*; import java.util.*; public class AbstractListDemo { public static void main(String[] args) { // create an empty list with an initial capacity AbstractList<Integer> list = new ArrayList<Integer>(5); // use add() method to add elements in the list list.add(15); list.add(20); list.add(25); // prints all the elements available in list for (Integer number : list) { System.out.println("Number = " + number); } } } Output: Number = 15 Number = 20 Number = 25 Program 2: Java // Java code to illustrate add(Object o) import java.io.*; import java.util.*; public class ArrayListDemo { public static void main(String[] args) { // create an empty list with an initial capacity AbstractList<String> list = new ArrayList<String>(5); // use add() method to add elements in the list list.add("Geeks"); list.add("For"); list.add("Geeks"); // prints all the elements available in list for (String str : list) { System.out.print(str + " "); } } } Output: Geeks For Geeks Reference: https://docs.oracle.com/javase/7/docs/api/java/util/AbstractList.html#add(E) Create Quiz Comment S shubhamsrivastava1490 Follow 0 Improve S shubhamsrivastava1490 Follow 0 Improve Article Tags : Java Technical Scripter Technical Scripter 2018 Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like