Java ListIterator remove() Method

The remove() method of ListIterator interface is used to remove the last element from the list which is returned by next() or previous() method. The above method can only be called if the add(E) has not been called.

Syntax

Parameters

NA

Specified by:

remove in interface Iterator<E>

Return

NA

Throws:

UnsupportedOperationException- If the given remove operation is not supported by the list iterator.

IllegalStateException- If neither the next() nor the previous() method has been called.

Example 1

Test it Now

Output:

The list for the vehicles is given as :[Car, Truck, Bike, Cycle]
Before remove() method is called. : [Car, Truck, Bike, Cycle]
After remove() method is called.: [Car, Bike, Cycle]

Example 2

Test it Now

Output:

The list for the marks is given as :[55.0, 69.0, 78.0, 89.0]
Before remove() method is called. : [55.0, 69.0, 78.0, 89.0]
After remove() method is called.: [55.0, 78.0, 89.0]

Example 3

Test it Now

Output:

The list for the ages is given as :[25, 30, 35, 40, 45]
Before remove() method is called. : [25, 30, 35, 40, 45]
After remove() method is called.: [25, 35, 40, 45]




Latest Courses