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
What are abstract methods in java?
Is null function in java?
How does predicate work in java?
Is null false in java?
Difference between comparator and comparable in java?
When do we need to use internal iteration? When do we need to use external iteration?
What is the purpose of javac exe?
How do you create an array in java?
What is an off by one error in java?
Why local variables are stored in stack?
What do you mean by garbage collection used in java?
What is rule of accessibility in java?
What is string pooling concept?
How many arguments can be passed to main ()?
explain the difference between jdk and jvm?