Aryan PrajapatKnowledge Contributor
How many overloaded add() and addAll() methods are available in the List interface? Describe the need and uses.
How many overloaded add() and addAll() methods are available in the List interface? Describe the need and uses.
List is an interface in the Java Collections Framework. The add() and addAll() methods are the main methods at the List interface. The add() method is used to add an element to the list, while the addAll() method is used to add a collection of elements to the list.
The List interface contains two overloaded versions of the add() method:
The first add() method accepts a single argument of type E, the element to be added to the list.
The second add() method accepts a variable number of arguments of type E, which are the elements to be added to the list.
The List interface also contains two overloaded versions of the addAll() method:
The first addAll() method accepts a single argument of type Collection, which is the collection of elements to be added to the list.
The second addAll() method accepts a variable number of arguments of type E, which are the elements to be added to the list.