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 disadvantage of java?
What is slash r?
What is package private scope in java?
What is stringjoiner ?
Explain exception chaining in java?
What are the methods available in a class?
What is treeset in java?
What is the difference between the paint() and repaint() methods?
Why pointers are not used in java?
When do I need to use reflection feature in java?
What do you understand by the term wrapper classes?
How do you override a variable in java?
Explain the importance of thread scheduler in java?
What is a protected method?
Who developed java?