Java, HashMaps and using Strings as the keys - does the string value get stored twice?

Posted by MalcomTucker on Stack Overflow See other posts from Stack Overflow or by MalcomTucker
Published on 2010-03-13T09:45:47Z Indexed on 2010/03/13 9:55 UTC
Read the original article Hit count: 304

Filed under:
|
|
|

If I have a HashMap that looks like this:

HashMap<String, MyObject>

where the String key is a field in MyObject, does this string value get stored twice?

So when I add entries:

_myMap.put(myObj.getName(), myObj);

Am I using double the String size in terms of memory? Or does Java do something clever behind the scenes?

Thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about hashmap