iterator hasnext() returns true but next() throws NoSuchElementException

前端 未结 2 399
夕颜
夕颜 2020-12-21 07:44

When I debugged my code I found that the hasNext() method of Iterator returned true, but the next() method threw NoSuchEl

2条回答
  •  独厮守ぢ
    2020-12-21 08:37

    When you say "debugged my code" do you mean debug using a debugger, like in Eclipse?
    If your evaluated expression (Expressions tab in Eclipse) includes itrest.next() then the debugger invokes the next() method and modifies the state of your Iterator, without your code being aware of it.
    Try debugging this either without evaluating itrest.next() or with log messages

提交回复
热议问题