The following example code demonstrates How to Create a LinkedList for Days of Week in Java.
Here is a program that creates a linked list of days of the week in Java.
import java.util.LinkedList;
public class DayList {
public static void main(String[] args) {
// create a linked list
LinkedList<String> days = new LinkedList<String>();
// add elements to the linked list
days.add("Monday");
days.add("Tuesday");
days.add("Wednesday");
days.add("Thursday");
days.add("Friday");
days.add("Saturday");
days.add("Sunday");
// display the linked list elements using iterator
System.out.println("Days of the week: ");
for (String day : days) {
System.out.println(day);
}
}
}
This program creates a linked list of days of the week and displays its elements using an enhanced for loop.