String constant pool in java

String literal/constant pool: represents a special heap memory part which is used to store string constants or string literals.

JVM checks the string constant pool every time whenever a string literal is created. JVM will create a new object if string literal is not present in the string pool but no new object will be created in the pool if string literal is already present in the pool, a reference of the already existing object will be returned.

String str1 = "w3spoint";
String str2 = "w3spoint";

Java interview questions on String Handling

Content Protection by DMCA.com
Please Share