How do I iterate LinkedList elements using Iterator?

This example show you how to use the Iterator interface to iterate elements of a LinkedList.

package org.kodejava.example.util;

import java.util.List;
import java.util.LinkedList;
import java.util.Iterator;

public class LinkedListIterator {
    public static void main(String[] args) {
        List<String> grades = new LinkedList<>();

        // Iterates elements in LinkedList using Iterator.
        Iterator iterator = grades.iterator();
        while (iterator.hasNext()) {
            System.out.println("Grade: " +;

This program prints the following output:

Grade: A
Grade: B
Grade: C
Grade: D
Grade: E

Wayan Saryada

Founder at Kode Java Org
I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. You can support my works by donating here. Thank you 🥳

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.