Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

Java Iterating through LinkedList

import java.util.LinkedList;

class Main {
    public static void main(String[] args) {
        // Creating a linked list
        LinkedList<String> animals = new LinkedList<>();
        animals.add("Cow");
        animals.add("Cat");
        animals.add("Dog");
        System.out.println("LinkedList: " + animals);

        // Using forEach loop
        System.out.println("Accessing linked list elements:");
        for(String animal: animals) {
            System.out.print(animal);
            System.out.print(", ");
        }
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Java #Iterating #LinkedList
ADD COMMENT
Topic
Name
4+1 =