How many objects are created when we create String class
object using new operator?
Answer Posted / rana
Answer is 2
String s = new String ("ABC"); // creates new object in heap & also adds entry in string literal pool.
String s1 = s.intern(); // will copy the string from pool
System.out.println(s1);
@Ravi -
System.out.println(s1.hashCode()==s2.hashCode() );
will return same because of String generates its hashCode based on the characters it has. there is a formula for hashCode generation on string
s[0]*31^n-1 + s[1]*31^n-2 ..... + s[n-1]
s[0] - 1st characters ascii value
n - length of the string
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is the differences between c++ and java? Explain
What is the use of runnable interface?
What restrictions are placed on method overloading in java programming?
Does string isempty check for null?
What do you mean by inner class in java? Explain
How do you sort in java?
Which is bigger float or double java?
What are implicit objects in java?
What is vector?
What are the two environment variables that must be set in order to run any java programs?
Is static variable stored in heap?
Explain java coding standards for interfaces?
How to implement a multithreaded applet?
What if the main() method is declared as private? What happens when the static modifier is removed from the signature of the main() method?
What are the important features of Java 9 release?