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 are the states associated in the thread? : Java thread
What is floor math?
Difference between vector and arraylist.
what is nested class in java?
How do you declare a string variable?
Why is whitespace important?
Is simpledateformat safe to use in the multithreaded program?
What is t type java?
What is the default execution method in java?
In a program, initializing an array of 100 KB is throwing an out of memory exception while there is 100 MB of memory available. Why?
What are the three types of design patterns?
Is it possible to instantiate the abstract class?
What are the Class Libraries ?
What is Major and importance difference between for and foreach loop ?
What is a java predicate?