Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HashMap - Non primitive types only?

807591Apr 9 2008 — edited Apr 9 2008
Am I right in saying that a HashMap can only map non primitive data types? So for example, if I want to map char to int I have to map Character to Integer?

I seem to be wasting alot of time in an otherwise very efficient program, calling the .intValue() and .charValue() methods on the types Character and Integer. (As well as the time wasted declaring new Character(char) and new Integer(int) just to put in the HashMap). Is there any way that I could map, say char a-z on int 0-25? (Without having to use Character and Integer, and call the .*Value() methods.)

HashMap<Character, Integer> charConverter = new HashMap<Character, Integer>();

^That's what my code looks like at the moment. I am using java 1.6, Eclipse wouldn't let me compile without explicitly stating the kind of contents to be held in the HashMap.

Cheers

Finbarr
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 7 2008
Added on Apr 9 2008
4 comments
1,132 views