Allow us to now perceive with a primary instance, how characters are saved in reminiscence.
Instance 1: On this instance, we are going to retailer characters in variables.
Output: Right here, we are able to see that internally all of the characters are being saved as String and strings with the identical worth seek advice from the identical location within the reminiscence to scale back reminiscence utilization.
string true false
Instance 2: On this instance, we are going to retailer characters with the identical worth however at totally different reminiscence areas.
Output: We are able to observe, that now the character is being saved as an object and every new occasion of an object is allotted a brand new location within the reminiscence regardless that it comprises the identical worth.
object false true
Once we are storing characters utilizing simply citation(”) marks then variables having the identical worth are saved at similar location within the String Fixed Pool but when we use new key phrase then distinct reminiscence location is assigned to every worth even when they’ve the identical worth