The hashcode for a String object is computed as
s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
The question is why 31 is used? Answer is available at here
Search This Blog
Best Free Virtual Desktop Manager for Windows
IMO, Dexpot is the best. Although there are other alternatives.
Java HashMap: how it identify a key
Key object's equals() and hashCode() are used to identify the key in the HashMap. In other words, you may need to override equals() and hashCode() methods of the key class.
Note: TreeMap is a sorted map, so you need to let the Key class implements Comparable interface, implements compareTo() method.
See also this discussion.
Note: TreeMap is a sorted map, so you need to let the Key class implements Comparable interface, implements compareTo() method.
See also this discussion.
Java bidirectional map, one to one mapping, get key from value
- For one to one Mapping: google collections has BiMap which is an bidirectional map. (see how to use google collections in GWT)
- See also: Stackoverflow
How to use Google Collections in GWT
- check out the google collections source code
- svn checkout http://google-collections.googlecode.com/svn/trunk/ google-collections-read-only
- build a jar package using ant
- cd google-collections-read-only
- ant jargwt
- cd ..
- copy & add build/dist/google-collect-snapshot/google-collect-gwt-snapshot.jar to your eclipse project's build path
You also need to inherits the module file:
<inherits name='com.google.common.Collect.gwt.xml'/>
Subscribe to:
Posts (Atom)