020-003-007
Basic HashMap Operations
Easy
Problem Description
Basic HashMap Operations
In this problem, you will create a class that manages a HashMap<String, Integer> internally and implement methods to add entries, retrieve values, and get sorted entries.
Learning Objective: Understand the basics of managing key-value pairs with HashMap
Overview
Implement the following three methods in a class that internally manages a HashMap<String, Integer>.
Specifications
putAndGetSize(String key, int value)
- Add a key-value pair to the HashMap
- Return the size (number of entries) of the HashMap after adding
getValue(String key)
- Return the value corresponding to the specified key
getSortedEntries()
- Return all entries as a comma-separated string in
key=valueformat, sorted alphabetically by key - Example:
"apple=150, banana=100, cherry=300"
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up