Build a simple in-memory database that stores records under unique string keys. Each record consists of zero or more fields, with both field names and their values represented as strings.
Implement the InMemoryDB class:
-
void setData(String key, String field, String value)— stores the givenvalueunderfieldin the record identified bykey.- If the field already exists, update its value.
- If there is no record for the key, create one.
-
String getData(String key, String field)— retrieves the value of the specified field from the record identified bykey.- Return
""if either the record or the field is missing.
- Return
-
boolean deleteData(String key, String field)— deletes the specified field from the record identified bykey.- Return
trueif the field was deleted, orfalseif the key or field is absent from the database.
- Return
Ask AI Assistant

Ask AI Assistant
Ask me anything about this coding question!
Test Cases
Input
Output
Expected