what is the difference between String s="hello"; and String
s=new String("hello");?

Answer Posted / amit singh

not the difference both are the string
String s = "hello"
its aliteral string it will be in a pool
imagine that when you cretae the anothre string
String s1 = "hello"
thn ther is not new Styrin object wil cretae its will pick
from the pool where the literal strin g hello will presnet
so s>
----------"hello"

s1>
both pointing the same string
2)String s = new String("hello");
there are two string will create frist the litreal "hello"
then the other through the new String("hello"); which is
point through referenece s is pointed so there is always
create a new String which is pointed by the reference s
its not going to pick through the pool
amitsing2008@gmail.com
amit09mca(scjp 1.5 and manymore)

Is This Answer Correct ?    3 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is set sorted in java?

527


What is array and arraylist in java?

545


I want to persist data of objects for later use. What is the best approach to do so?

605


Can we overload the main() method?

562


What is the default value of byte datatype in java?

495






Explain about main() method in java ?

598


What is Java Reflection API? Why it’s so important to have?

617


What is an interface in java? Explain

591


How do you get length in java?

572


java program with complete 4 oops concepts implemented example

2741


What is meant by method overriding?

553


What is the exact difference in between Unicast and Multicast object? Where will it be used?

595


Can a abstract class be defined without any abstract methods?

574


How can we find the sum of two linked lists using stack in java?

582


What are the drawbacks for singleton class?

530