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
Post a Comment