Everytime I run this program that I want to display the memory address, it always output same result:
public static void main(String[] args) throws InterruptedException {
String foo = "a";
String foo2 = "a";
System.out.println(Integer.toHexString(foo.hashCode()));
System.out.println(Integer.toHexString(foo2.hashCode()));
foo = "a";
foo2 = "a";
System.out.println(System.identityHashCode(foo));
System.out.println(System.identityHashCode(foo2));
Thread.sleep(1000000);
}
The purpose of this is I am doing some performance test between Streams and Imperative style. So I would like to know if this value is cache, and determines if I should restart my pc or manually run garbage collection via JConsole / JvisualVm.