Why create a new map here? That's pretty heavy-weight. How about just allocating a Map.Entry<ImmutableBytesPtr, Integer> valueVsCount.size()], sorting it with Arrays.sort, and iterating through it like you're doing?