Efficient scheduling requires a clear mapping between descriptors and their numerical values. This project demonstrates the use of a HashMap to associate the days of the week with their ordinal numbers. The core focus is on Collection Iteration, specifically using the entrySet() method. This approach allows access to both the key and the value simultaneously during a single loop, providing a clean and efficient way to format and display associated data for the end user.
- Key-Value Mapping: Successfully associated
Stringkeys (Day names) withIntegervalues (Day numbers). - Efficient Iteration: Used
Map.Entryto traverse the collection, avoiding redundant lookups by key. - Formatted Presentation: Implemented custom string formatting to match the "Day: [Name], Number: [Value]" requirement.
- Type Safety: Utilized Generics to ensure data consistency within the
HashMap.
- Java 8+ (Collections Framework, Map.Entry)
- SchedulerApp: The main class responsible for populating the map and executing the formatted output logic.
Day: Monday, Number: 1
Day: Tuesday, Number: 2
Day: Wednesday, Number: 3
Project Structure:
JavaBasics_Task_449/
├── src/
│ └── com/yurii/pavlenko/
│ └── app/
│ └── SchedulerApp.java
├── LICENSE
├── TASK.md
├── THEORY.md
└── README.md
Code
package com.yurii.pavlenko.app;
import java.util.HashMap;
import java.util.Map;
public class SchedulerApp {
public static void main(String[] args) {
Map<String, Integer> weekDays = new HashMap<>();
weekDays.put("Monday", 1);
weekDays.put("Tuesday", 2);
weekDays.put("Wednesday", 3);
for (Map.Entry<String, Integer> entry : weekDays.entrySet()) {
System.out.println("Day: " + entry.getKey() + ", Number: " + entry.getValue());
}
}
}This project is licensed under the MIT License.
Copyright (c) 2026 Yurii Pavlenko
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...
License: MIT