![]() |
Sponsored Link •
|
Advertisement
|
Advertisement
|
This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.
Message:
> Is it possible to use 1 value to get a hash key and to then store a different answer for the element > EG. > word1 = dog > we get the hashkey for word1 but instead of storing word1 as the element we store word2 > Any suggestions??
Keys in a hashtable are not necessarily unique. You could have to keys labled word1. However, doing so won't help you because hashtable.get(Object) returns the first one it finds so it would always return "dog" in this case. In my current project I am making extensive use of hashtables because the column content from the data could vary at the drop of a hat. I have methods to write hashtable entries where the code looks like this. public void setKeyValue(Object hKey, Object hValue) if ( ! "A".equals( getState() ) ) isKey() checks to see if a key exists, its code is included below for reference. getCoreData() returns a reference to the coreData hashtable of the object. public boolean isKey(Object hKey) hashtable.containsKey() returns true if the key exists and false if it does not. This simple vehicle allows us to quickly check for the existence of a proposed key. This model includes three potential keys; hKey (The actual key) The logic in the class checks the state of the key on any attempt to read the key and if it has been deleted ignores the request, if it has been edited the request is automatically rerouted to the changed key. This allows us to roll back any changes without having to tie up database resources. Regards,
Replies: |
Sponsored Links
|