New to hashtables with a simple question. For some reason googling hasn’t gotten me a straight answer. Say I’ve got an
<int,String> hashtable set up:
and I want to change “bird” to “fish” (and leave the index the same). Can I just do a simple
put, or do I need to delete the entry, or what?
If a mapping to the specified key already exists, the old value will be replaced (and returned). See
For multi-threaded environment, I’d recommend
ConcurrentHashMap or another
ConcurrentMap implementation. Though
Hashtable is synchronized, there are more sophisticated implementations available now for concurrent mapping, such as Guava’s
Also keep in mind the
Map is going to have the type parameters
<Integer, String> since primitive type parameters aren’t supported.
hmmm ,just need add a line
to see what’s amazing happens
Returns: the previous value of the specified key in this hashtable, or null if it did not have one