Java ListIterator set() 方法2025 年 3 月 22 日 | 阅读需 2 分钟 ListIterator 接口的 set() 方法用于使用给定元素替换由 next() 或 previous() 返回的最后一个元素。只有在 neither remove() nor add(E) 方法未被调用时才能调用此方法。 语法参数上述方法只需要一个参数
返回不适用 抛出UnsupportedOperationException- 如果列表迭代器不支持给定的 set 操作。 ClassCastException- 如果指定元素的类不被列表迭代器支持。 IllegalArgumentException- 如果给定元素的某些方面阻止其被添加到列表中。 IllegalStateException- 如果 next() 和 previous() 方法都未被调用。 示例 1输出 The list of the names of the students is given as: [Ravi, Tina, Payal, Aashi] Before using the set() method : Ravi Tina Payal Aashi After using the set() method : Ravi Tina Payal None 示例 2输出 The list of marks of the students is given as: [44.7, 67.0, 78.0, 98.9] Before using the set() method : 44.7 67.0 78.0 98.9 After using the set() method : 44.7 67.0 78.0 12.4 示例 3输出 The list of age of the students is given as: [23, 56, 34, 98] Before using the set() method : 23 56 34 98 After using the set() method : 23 56 34 12 |
Java ListIterator previous() 方法 previous() 方法用于从列表中返回前一个元素,并将光标移动到后向位置。该方法可用于向后迭代列表。 语法 public E previous() 参数 NA 返回 上述方法...
阅读 3 分钟
Java ListIterator remove() 方法 remove() 方法用于移除由 next() 或 previous() 方法返回的最后一个元素。此方法只能在未调用 add(E) 方法的情况下调用。 语法 void 参数 NA 指定者: Iterator<E> 接口中的 remove()...
阅读 3 分钟
Java ListIterator next() 方法 next() 方法用于返回列表中的元素。此方法用于迭代列表。 语法 public E next() 参数 NA 指定者: Iterator<E> 接口中的 Specified by: Return 上述方法用于返回列表中的元素...
阅读 2 分钟
Java ListIterator previousIndex() 方法 previousIndex() 方法用于返回由 previous() 调用返回的给定元素的索引。如果迭代器位于列表的开头,则该方法可能返回 -1。
阅读 2 分钟
Java ListIterator hasPrevious() 方法 hasPrevious() 方法用于检索并移除双端队列的头部。该方法与 poll() 方法的区别仅在于,如果双端队列为空,则会抛出异常。 语法 boolean hasPrevious() 参数 NA 返回 上述方法...
阅读 2 分钟
Java ListIterator has() 方法 has() 方法用于在向前遍历列表时,如果列表迭代器包含更多元素,则返回 true。 语法 boolean has() 参数 NA 指定者: Iterator<E> 接口中的 has() 返回 上述方法用于返回 true...
阅读 2 分钟
Java ListIterator add() 方法 ListIterator 接口的 add() 方法用于将给定元素插入到指定的列表中。该元素将在 next() 方法可能返回的元素之前自动插入。 语法 void add(E e) 参数 上述方法只需要一个参数:元素 'e'...
阅读 2 分钟
Java ListIterator nextIndex() 方法 nextIndex() 方法用于返回由 next() 方法返回的元素的索引。 语法 int nextIndex() 参数 NA 返回 上述方法用于返回由 next() 方法返回的元素的索引。...
阅读 3 分钟
方法 方法 add() has() hasPrevious() Index() () previousIndex() previous() remove() set() 主题 ...
阅读1分钟
我们请求您订阅我们的新闻通讯以获取最新更新。
我们提供所有技术(如 Java 教程、Android、Java 框架)的教程和面试问题
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India