1).what is the difference between below examples
String s="vijay";
String s=new String("vijay");
Answer Posted / ravi
Guys please don't miss guide.
Karun you r absolutely right, but there is one big
difference between them
String s="vijay"; --> This is string literal
String s=new String("vijay"); --> String Object
Definitely first one gives the better performance than
second one, why because..
JVM maintains an internal list of references for interned
Strings( POOL of unique strings) to avoid duplicate string
objects in heap memory. when ever the JVM loads string
literals from class file and executes, it checks whether
that string exists in the internal list or not. If it is
already exists in the list then it does not create new
string and it uses the references to the existing String
object. JVM does this type by checking tinternally for
string literal but not for string object which it creates
through 'new' keyword
You can explicitly force the JVM todo this type of checking
for string objects which are created through 'new' keyword
using "String.intern()" method. This forces the JVM to check
the internal list and use the existing String object if it
is already present.
| Is This Answer Correct ? | 26 Yes | 0 No |
Post New Answer View All Answers
take an array with -ve and +ve value both.find out the nearest value of 0(zero).if two values are same like(-2 and +2)then extract +2 is nearest of 0(zero).
how to create daemon thread in java?
What is void class in java?
What is the set interface in java programming?
What is the list interface in java programming?
What do you understand by Header linked List?
What is a short in java?
Is java written in c?
What is the relationship difference the canvas class and the graphics class?
What is the major drawback of internal iteration over external iteration?
What is the size of integer?
What is a class reference?
What are thread groups?
Is arraylist sorted in java?
what are the states associated in the thread? : Java thread