what is the difference between String s="hello"; and String
s=new String("hello");?
Answer Posted / khan
Both are the way to create a String object
String s = "hello";
this is literal String if there is "hello" string presnet
in poll it doesn't create the new String "hello" it will
pick it form the pool and refer it
otherwise it will create the String "hello"
but in String s = new String("hello");
first the literal hello pick from the pool if it present
and pass to the overloaded String class constructor,
otherwise it will create and pass to the
overloaded constructor of String String(String s)
and create the new string object Through new String
("hello");
you shoul to checkit through
some coding what happens
String s = "hello";
String s1 = "hello";
String s3 = new String("hello");
s==s1 return true
s.equals(s1) return true
s==s3 return false
s.equals(s3) return true
and "previous answers also true which gave by other person"
scjp,scwcd,scbcd
| Is This Answer Correct ? | 11 Yes | 0 No |
Post New Answer View All Answers
What is java abstraction with example?
What is final, finally, finalize?
Can we declare the static variables and methods in an abstract class?
Why super is first line in java?
What are the supported platforms by java programming language?
What is java used for on a computer?
Explain about the performance aspects of core java?
What are the 7 types of characters?
What are operators and its types?
Can a class be private in java?
When should I use singleton?
What does it mean to flush a file?
Is string serializable in java?
Write a program to find the greatest of three numbers in java?
Is arraylist dynamic in java?