To a certain degree, this is about style. Therefore you should rather ask the people working on this code base about what they consider the best name in your project. It doesn't matter what the "global best practice" is here, what matters is what works best for you!
Nonetheless, the clear winner is getCountiesByState(myCounties)
:
- there is no need to specify the collection type anywhere (
fooByBar
already tells us that this is about a mapping!)
- and
sortToState()
is a bit misleading, as it is not making clear that it will return a map!
As that sorting aspect seems to be important, why not getSortedCountiesByState(myCounties)
or getCountiesSortedByState(myCounties)
or getCountiesBySortedStates(myCounties)` ...