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

What is the default value of local and global variables?

559


What is unicode full form?

546


What are the restrictions imposed by a Security Manager on Applets?.

2059


List down the methods and interfaces of collection class in java.

535


How many days will it take to learn java?

508






How to create an immutable class?

564


Is java a digit method?

508


What is thread life cycle in java?

578


What are the different http methods?

523


What do you understand by java virtual machine?

700


What are features of java?

559


What does exp mean in math?

527


What is exception in java?

563


What are the 6 boolean operators?

547


I want to re-reach and use an object once it has been garbage collected. Define how it’s possible?

567