This might be a silly question, but I have never found a satisfying way to name a variable of type HashMap<K,V> in Java. For example – lets say I have a HashMap where every bucket is a <K,V> pair where K is a String say representing “State” and V is an Integer representing the number of counties the state has.
Should the HashMap be named as “mapStateCounty“, “stateToCountyMap“, etc. ?
Which one seems logically more appealing and intuitive to understand without sounding confusing and verbose?
I like this question because Java does not allow map access via an operator like
[]. In other languages we could say things likeor
or
or (in Scala, this is cool)
and on and on. None of these work in Java, because of that silly
getword!Indeed!
EDIT: I actually think
countyCountsis the best answer (IMHO); I was just making the point that the need forgetlimits one’s choices.