Allow us to now perceive with a fundamental instance, how characters are saved in reminiscence.
Instance 1: On this instance, we are going to retailer characters in variables.
Output: Right here, we will 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 cut back reminiscence utilization.
string true false
Instance 2: On this instance, we are going to retailer characters with the identical worth however at completely different reminiscence places.
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 although it incorporates 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