Home » Java Collections emptyListIterator() Method with Examples

Java Collections emptyListIterator() Method with Examples

by Online Tutorials Library

Java Collections emptyListIterator() Method

The emptyListIterator() method of Java Collections class is used to get a List Iterator that has no elements.

Syntax

Following is the declaration of emptyListIterator() method:

Parameter

This method does not accept any parameter.

Returns

The emptyListIterator() method returns the list Iterator that has no elements..

Exceptions

NoSuchElementException

Compatibility Version

Java 1.7 and above

Example 1

Test it Now

Output:

Output: false  

Example 2

Test it Now

Output:

Exception in thread "main" java.util.NoSuchElementException  at java.base/java.util.Collections$EmptyIterator.next(Collections.java:4190)  at myPackage.CollectionsEmptyListIteratorExample2.main(CollectionsEmptyListIteratorExample2.java:10)  

Example 3

Test it Now

Output:

0  -1  nextIndex() and previousIndex() always returns 0 and -1.  

You may also like