Commit 29d1968
committed
feat: Demonstrate key, value, and entry iteration using Java HashMap
🧠 Logic:
- Created a `HashMap<String, Integer>` to store student names and their ages.
- Populated the map with three entries: Alice, Bob, and Charlie.
- Used enhanced for-loops to:
- Print all keys using `keySet()`.
- Print all values using `values()`.
- Print key-value pairs using `entrySet()` with `Map.Entry`.
- Effectively illustrates how Java maps (like dictionaries) can be traversed in multiple ways.
Signed-off-by: Somesh diwan <[email protected]>1 parent 31cf982 commit 29d1968
1 file changed
+4
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
| 7 | + | |
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
15 | | - | |
16 | 14 | | |
17 | | - | |
18 | | - | |
| 15 | + | |
19 | 16 | | |
20 | 17 | | |
21 | 18 | | |
22 | 19 | | |
23 | 20 | | |
24 | | - | |
25 | | - | |
| 21 | + | |
26 | 22 | | |
27 | 23 | | |
28 | 24 | | |
29 | 25 | | |
30 | | - | |
31 | 26 | | |
32 | | - | |
33 | | - | |
| 27 | + | |
34 | 28 | | |
35 | 29 | | |
36 | 30 | | |
| |||
0 commit comments