-1

I have a hash map in java 8. I want to print reference of hash map instead of its content. In java 8 when I print hash map using its to String method it prints content. How can I get object reference printed?

Map<String,String> m = new HashMap<String,String>();
m.put("abc","def");
System.out.println("m is"+m); //need to get object reference not content
Michael Markidis
  • 4,163
  • 1
  • 14
  • 21
user1846749
  • 2,165
  • 3
  • 23
  • 36

1 Answers1

4

You can do this to get what the Object.toString method would return:

String s = m.getClass().getName() + "@" + Integer.toHexString(m.hashCode());
System.out.println(s);
Michael Markidis
  • 4,163
  • 1
  • 14
  • 21