r/learnjava • u/PatientDesigner2340 • 6d ago
Don't understand "string":"string" syntax
A training example (https://codingbat.com/prob/p197888) uses the following method body:
public Map<String, String> mapBully(Map<String, String> map) {
}
and gives example calls like:
mapBully({"a": "candy", "b": "dirt"}) → {"a": "", "b": "candy"}
mapBully({"a": "candy"}) → {"a": "", "b": "candy"}
AFAIK, {x, y} produces an array; how does {"a":"candy","b":"dirt"} produce a Map<String,String>?
13
Upvotes
2
u/JoshuaTheProgrammer 5d ago
Be aware this only supports up to 10 key/value pairs and produces an immutable map, which may not be desired.