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
- Why string objects are immutable in java?
- How many ways we can create the string object?
- Why java uses the concept of string literal?
- String vs StringBuffer vs StringBuilder in java
- How to create immutable class in java?
- What is the purpose of toString() method in java?
- Is string a keyword in java?
- Is string a primitive type or derived type?
- What is string constant pool in java?
- What are mutable and immutable objects in java?
- What is string intern in java?
- Can we call string class methods using string literals?