• Post Reply Bookmark Topic Watch Topic
  • New Topic

Object References  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Please explain the output of following code.

HashMap hmap= new HashMap();
String a = "original value";
hmap.add("key",a);
a="changed value";
String b = (String)hmap.get("key");
System.out.println(b);

----------
Output is : "original value".
I expected it to be "changed value".
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reading this and then especially this should straighten everything out for you.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!