1).what is the difference between below examples
String s="vijay";
String s=new String("vijay");
Answer Posted / vijay
yes karun and ravi u both are right...!!
dear friends there is small difference b/w both string
declaration but both have create huge differences.
String s="vijay"; // string literal
that means it create one object and one reference and object
will be created in string pool.
String s= new String("vijay"); //string object
that means it create two object and one reference and one
object will be created in string pool and another on heap.
and difference what ravi want to say is ....if
String s="vijay";
String s1="vijay";
means here s and s1 both refer the same object whereas
String s=new String("vijay");
String s1=new String("vijay");
here these reference s and s1 refer refer 2-different
object.
that is why the first one give the better performance.
| Is This Answer Correct ? | 6 Yes | 0 No |
Post New Answer View All Answers
What is null statement?
Is java an open source?
What is immutability in java?
What is meant by singleton class?
Explain about fail fast iterators in java?
Which object oriented concept is achieved by using overloading and overriding?
How to remove the trailing spaces from a string?
What is passing by reference in java?
What are actual parameters?
what is singleton in java?
What are default methods ?
What is the difference between procedural and object-oriented programs?
What is codebase?
What will be the output of round(3.7) and ceil(3.7)?
What does function identity () do?