I want to confirm if two String variable created is pointing to the same memory.The way I did it with normal class
Ideone a=new Ideone();
Ideone b=a;
System.out.println(a+" "+b);
Output
Ideone@106d69c Ideone@106d69c
The output produced here is not the exact memory address but it gave hex code which are same and by which I can say that they both are pointing to same memory address or values.
But in case of String
String a="helloworld";
String b="hello";
String c=b+"world";
System.out.println(a+" "+c);
Output
helloworld helloworld
Its the expected output and I know that a,b,c
are created in the pool as they are compile-time constants and a
and c
do not point to same memory .But is there any way I can get the Object representation of string like String@23122
as to get the hex code of that object to confirm that a
and c
do not point to same memory?
Because in case creating string by new String("helloworld")
new memory is allocated to string.
I have searched it but dint find anything similar to my problem.
Thanks in advance.