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.
Further Reading
Understanding Enterprise Java Beans
- Android
- Angular
- ASP.NET
- AWS
- Bootstrap
- C
- C#
- C++
- Cloud Computing
- Competitions
- Courses
- CSS
- Deep Learning
- Django
- Dot Net Framework
- HTML
- IoT
- Java
- JavaScript
- Kotlin
- Machine Learning
- MEAN Stack
- MERN Stack
- MongoDB
- NodeJS
- PHP
- Power Bi
- Projects
- Python
- Scratch 3.0
- Solidity
- SQL
- TypeScript
- VB.NET
- Web Designing
- XML
