Re: Using char[] as key in a HashMap
Attila Szegedi <[email protected]> Wed, 30 Jan 2008 13:23:53 +0100
| Newsgroups | gmane.comp.windows.devel.java.advanced |
|---|---|
| Message-ID | <[email protected]> |
Or use the Trove library that allows you to plug in a custom hashing strategy into the map. Attila. On 2008.01.30., at 9:37, neil wrote: > Why not use a TreeMap instead. This may use less memory than the > HashMap > anyway and you can pass an external Comparator in so you don't need > to wrap > the char[]. > > - Neil > > On Wed, 30 Jan 2008 02:24:01 -0600, Avinash Lakshman > <[email protected]> wrote: >> That's awesome. Thanks >> >> A >> >>> Date: Tue, 29 Jan 2008 23:28:33 -0800 >>> From: [email protected] >>> Subject: Re: [ADVANCED-JAVA] Using char[] as key in a HashMap >>> To: [email protected] >>> >>> Just wrap it with CharBuffer.wrap(char[]): >>> http://java.sun.com/j2se/1.5.0/docs/api/java/nio/CharBuffer.html >>> >>> Bob >>> >>> On Jan 29, 2008 11:24 PM, Avinash Lakshman <[email protected]> >> wrote: >>> >>>> Hi All >>>> >>>> In the application that we are building we have the need to >>>> maintain >> some >>>> objects in memory in a HashMap keyed by a String. But it seems that >> the >>>> overhead of the String is such that the overhead is more than the >> length of >>>> the characters in the String. I was thinking of reducing the memory >>>> footprint significantly by replacing the key with a char[] of the >> String. >>>> How can I achieve this? How can I implement the hashCode() and >> equals() of >>>> char[]? Do I have to do it with a class that wraps the char[]? =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com