One Two Three
One Two Three

Reputation: 23517

alternative (ie., better choice) for Hashmap on character

Just as EnumMap is the better choice of map when working with enum, is there a better choice of map (rather than the generic HashMap that everybody uses) for dealing with character?

Characters are kind of similar to enum-members in that there are a definite number of them, so I thought there might be a 'special' kind of map for them?

[Edit] By 'better' I meant 'faster' and uses 'less memory'

Upvotes: 1

Views: 102

Answers (1)

Sanjay Manohar
Sanjay Manohar

Reputation: 7026

I think I understand your question. If there are a finite number of chars, you should be able to economise on the size of the Hash map.

But you are overlooking the internationalisation thing maybe? There aren't really that 'finite' a number of chars. (real unicode has variable-length encoding etc) So I doubt there would be a good way of economising.

If you are in a particular language with e.g. 26 characters, you could consider making your own enum (or simpler, an array) for the job. If you are after a i18n-independent answer, I can't help...

Upvotes: 2

Related Questions