リストに要素が1つしかない場合は、より明確になります。たとえば、「b」としましょう。hasNext()実際にtrueを返し、それnext()を読み取り、その後反復が終了します。
説明:
Iterator<Object> it= list.iterator()空でないリストを呼び出した場合(要素が 1 つしかない場合でも) true、. hasNext()これは、反復子が最初の要素の前に初期化されるためです。
  b u n g i o r n o
 ^
 i - iterator
呼び出すと、次next()の 2 つのことを行います。
- イテレータの前の要素を読み取り、
- 読み取ったばかりの要素の直後、次の要素の前にイテレータを移動します。
あなたの例では、「b」を出力し、「u」の前で停止します。
  b u n g i o r n o 
   ^
   i
そして終了直前:
  b u n g i o r n o
                 ^
                 i
実際には次の値「o」があります。を呼び出すと、next()その値が読み取られ、 の後にジャンプしますo。これ以上の要素はありません。hasNext()false と表示され、呼び出すnext()と例外が発生します。
技術的な詳細:
イテレータの実装方法の基本的な考え方は次のIteratorとおりです。-が であるかどうかを確認するだけです。-を返し、次の要素を表示するように設定します。iterator()ListnexthasNext()next!= nullnext()nextnext
これはjava.util.ArrayListIterator です (一部の詳細は省略されています)。
public Iterator<E> iterator() {
     return new Itr();
}
private class Itr implements Iterator<E> {
     int cursor;       // index of next element to return
     int lastRet = -1; // index of last element returned; -1 if no such
     int expectedModCount = modCount;
     public boolean hasNext() {
         return cursor != size;
     }
     public E next() {
         checkForComodification();
         int i = cursor;
         Object[] elementData = ArrayList.this.elementData;
         cursor = i + 1;
         return (E) elementData[lastRet = i];
     }
 }