Acetamide Acetamide - 25 days ago 8
Java Question

What is Iterator Implementation in Linked List using Java?

I was creating an inventory to store books information. And I have done with insertion, deletion, search and other function.
Then, I saw the exercise requirement has a line said that:

You are also required to implement an Iterator for your linked list.

I look up online for the Iterator and watched some videos, still couldn't understand what an iterator is and how to implement into my linked list.

Anyone can help me? Thank you.

Answer

An iterator basically allows you to iterate over a Collection. I don't know what is meant by:

You are also required to implement an Iterator for your linked list

But I assume, it want's you to iterate over your Collection using an Iterator and do your operations like this.

Iterating through a Collection using an Iterator:

List<Object> list = new LinkedList<>();
Iterator<Object> it = list.iterator();
while(it.hasNext()){
    Object obj = it.next();
    // Do stuff
}

If this is not what you are looking for, it seems I missunderstood the question.