Java Collections emptyListIterator() 方法

2025年3月21日 | 阅读 1 分钟

Java Collections 类的 emptyListIterator() 方法用于获取一个不包含任何元素的 List Iterator。

语法

以下是 emptyListIterator() 方法的声明:

参数

此方法不接受任何参数。

返回值

emptyListIterator() 方法返回一个不包含任何元素的 List Iterator。

异常

NoSuchElementException

兼容版本

Java 1.7 及以上版本

示例 1

输出

Output: false

示例 2

输出

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)

示例 3

输出

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