3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

LinkedListのiterator()を呼ぶと結局return listIterator();している

Last updated at Posted at 2014-09-10

※src.zip は java7 のものを見てます。

ListとIteratorの関係がよくわからなくなったので調べていたところ、ListIteratorというものを見つけた。
ListIterator は、next()だけじゃなくてprevious()もあるよ、というクラスらしい。
そんな需要があるのか、へーと思ってたら、なんとLinkedListのイテレートにはListIteratorしか使えないということになってた。

AbstractSequentialList.java※LinkedListのスーパークラス
    /**
     * Returns an iterator over the elements in this list (in proper
     * sequence).<p>
     *
     * This implementation merely returns a list iterator over the list.
     *
     * @return an iterator over the elements in this list (in proper sequence)
     */
    public Iterator<E> iterator() {
        return listIterator();
    }

ArrayList.java#iterator() はそんなことはないし、なぜだろう。

3
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?