Home » Java ListIterator add() Method with Examples

Java ListIterator add() Method with Examples

by Online Tutorials Library

Java ListIterator add() Method

The add() method of ListIterator interface is used to insert the given element into the specified list. The element is inserted automatically before the next element may return by next() method.

Syntax

Parameters

The above method requires only one method:

  1. The element ‘e’ that needs to be inserted.

Return

NA

Throws:

UnsupportedOperationalArgument– If the add() method is not supported by the given list iterator.

ClassCastException– If the class of some of the element avoids it from being added into the list.

IllegalArgumentException– If some of the element avoids it from being added into the list.

Example 1

Test it Now

Output:

Hello  Everyone  

Example 2

Test it Now

Output:

The list is given as:   66.9  70.4  34.6  

Example 3

Test it Now

Output:

The list of alphabets is given as: [t, h, j, m]  

You may also like