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
Is set sorted in java?
What is array and arraylist in java?
I want to persist data of objects for later use. What is the best approach to do so?
Can we overload the main() method?
What is the default value of byte datatype in java?
Explain about main() method in java ?
What is Java Reflection API? Why it’s so important to have?
What is an interface in java? Explain
How do you get length in java?
java program with complete 4 oops concepts implemented example
What is meant by method overriding?
What is the exact difference in between Unicast and Multicast object? Where will it be used?
Can a abstract class be defined without any abstract methods?
How can we find the sum of two linked lists using stack in java?
What are the drawbacks for singleton class?