I have two Strings:
String s = "ABC";
String s1 = new String("ABC");
In theory, If I am not wrong two objects are created in this case. I can verify that using hashcode().
public static void main(String[] args) {
System.out.println(s.hashCode());
System.out.println(s1.hashCode());
}
}
Output:
2125849484
2125849484
If I am not wrong, hashcode()
only help us in verifying that both the strings having similar value assigned to it "ABC", because of that hashcode value is same. What about that 2nd object which is created in heap memory? How can we verify that whether it is created or not.