HashMap - Non primitive types only?
807591Apr 9 2008 — edited Apr 9 2008Am 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