Commit 5ef321f
committed
feat: add ConcurrentSkipListMapDemo1 with string-key example
What
- Created `ConcurrentSkipListMapDemo1` class.
- Demonstrated `ConcurrentSkipListMap<String, Integer>` usage.
- Inserted fruit names as keys and integers as values.
- Printed map contents showing natural key ordering.
Why
- Extends prior demo by using `String` keys instead of `Integer`.
- Highlights that `ConcurrentSkipListMap` maintains **lexicographic order** for strings.
- Reinforces thread-safe + sorted map usage in simple scenarios.
How
- Initialized a `ConcurrentSkipListMap<String, Integer>`.
- Added entries: `Apple=2`, `Banana=4`, `Mango=3`.
- Printed output, which automatically sorts keys: `{Apple=2, Banana=4, Mango=3}`.
Logic
- Keys in `ConcurrentSkipListMap` are always kept sorted.
- For `String` keys, natural ordering is lexicographic.
- Thread-safe without needing external synchronization.
Real-world applications
- Useful for maintaining sorted dictionaries or lookup tables in concurrent environments.
- Can efficiently support prefix-based queries or range operations with string keys.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent cdca1ac commit 5ef321f
File tree
1 file changed
+40
-0
lines changed- Section 25 Collections Frameworks/Map Interface/Concurrent HashMap/Concurrent Skip List Map/src
1 file changed
+40
-0
lines changedLines changed: 40 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
0 commit comments