Each time you create a string literal, the JVM checks the string constant pool first. If the string already exists in the pool, a reference to the pooled instance is returned. If string doesn't exist in the pool, a new string instance is created and placed in the pool.
2)By new keyword
In such case, JVM will create a new string object in normal(non pool) heap memory and the literal "Welcome" will be placed in the string constant pool. The variable s will refer to the object in heap(non pool).
String s=new String("Welcome")
Liked By
Write Answer
How many ways we can create the string object?
Join MindStick Community
You have need login or register for voting of answers or question.
Anonymous User
25-Apr-2015There are two ways to create String object:
String s="welcome";
String s=new String("Welcome")