hashmap - How to get the Object Reference having the hashcode or other Unique String in Java -


this issue. im storing data database table has column store hashcode (or can other unique string such id because jvm can re-locate objects, changing hashcode). once string want access object mapped string. can hashmap like:

concurrenthashmap<string, myclass> myclassdictionary;

the average of objects store +800. can take other options avoid kind of things want know if of know better way using hashmap.

i found referenceable interface implement, can check out in next link: http://docs.oracle.com/javase/jndi/tutorial/objects/storing/reference.html

thanks reading.

you can use key in hashmap immutable. string nature immutable, means object cannot changed, if tries change object, new 1 created , original remains is. safe if using unique strings key. advantage of using immutable keys in hashed collection that, key object preserved or unchanged. , there no chance mistake , change key, , leading problem lose reference value. if key not immutable , changed other place in code. never able fetch associated value key. refer memory leak in java.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

android - Inheriting from Theme.AppCompat* -