If I have a completely empty String Pool in Java and I do the following, does the string object 'Hello' be added to the string pool.?
String myStr = new String('Hello');
I know that subsequent calls to new String('Hello'); will create a new string object but not add it to the pool, but what about the first time if 'Hello' is not already in the pool?
Edit: Basically, I need to know why the following prints false:
String myStr = new String("Hello");
print(myStr=="Hello");
If, on first call, new String("Hello"); adds Hello to the pool. Then in the comparison code, we are comparing the pool-resident object 'Hello' with the literal 'Hello' (right side of the ==). Therefore, isn't the left side of the == pointing to the same object (in the pool) as the right side?