How should I name a java.util.Map? [closed]
Solution 1:
A Map maps something to something else.
I like to use names like uidToPerson
. "To" being the shortest unambiguous way I can think of to show that I have a map.
Edit:
I'll add that I prefer to have the map named this way, because "key" and "value" appear in that order in the name. As opposed to valueByKey
. In mapping operations, the key comes first. You put(key, value)
or get(key)
that gives a value.
Of course this is a matter of personal preference.
Solution 2:
I tend toward something like parametersByName
to leave no confusion about what the contents of the Map
are. You never know when you're going to have to revisit code that you haven't looked at in a long time.
In Java, I find it unnecessary to include the name of the data structure (like parametersByNameMap
) since the typing is explicit.