This content has been marked as final. Show 4 replies
A primitive is not an object, you can't have a reference to it. You need to wrap them in an Integer object and store that. Use a Map as your hashtable (HashMap for example). Then you can simply do
Map mymap = new HashMap(); mymap.put("myint1", new Integer(5));
The colt library has some hash maps and collections that work with different kind of primitives:
Also, I think the jakarta commons project at apache may have similar things, but I've never used it...
If your really want to store primitive values and
want to access them by hash, you would have
to write your own Hashtable that uses a int
as underlying storage. This is definitly not part
of JRE and I am not aware of any 3rd party library
that does that. It's even questionable if you could
get any performance win out of it. However if you do,
let me know.
IBM has an article on a collections class called Trove that can take primitives as keys and values: