java - printing the address of the string instances -


package com.testproject; public class javasample {      public static void main(string[] args) {          string mystring1 = new string("sample1");         system.out.println(mystring1);         string mystring2 = new string("sample2");         system.out.println(mystring2);     } } 

in above piece of code how print address of these strings created "sample1" , "sample2", need print memory location of string object mystring1 , mystring2

if mean "address" this:

system.out.println(new object()); 

java.lang.object@31ec0130

then can do,

string s = new string("one"); system.out.println(integer.tohexstring(s.hashcode())); 

1ae66

since think "address" hashcode() converted hex string.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -