Skip to content
Snippets Groups Projects
Commit bfb5e96d authored by Martin Schmollinger's avatar Martin Schmollinger
Browse files

Iterator: use hasNext() in method next() to reduce code redundancy

parent 2a89d249
No related branches found
No related tags found
No related merge requests found
...@@ -130,7 +130,7 @@ public class LinkedList<E> implements List<E> { ...@@ -130,7 +130,7 @@ public class LinkedList<E> implements List<E> {
return next!=null; return next!=null;
} }
public E next() { public E next() {
if (next==null) throw new NoSuchElementException(); if (!hasNext()) throw new NoSuchElementException();
E value = next.data; E value = next.data;
next = next.next; next = next.next;
return value; return value;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment