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
Write the algorithm to check the number non-leaf nodes in a tree.
What is indexof?
Can we have multiple classes in a single file?
What is meant by vector class, dictionary class, hash table class, and property class?
What is the difference between final, finally and finalize()?
What is a arraylist in java?
What is a string what operation can be performed out with the help of a string?
How an object is serialized in java?
What is treeset in java collection?
What are the types of methods in java?
How to implement a multithreaded applet?
Explain the difference between a Thread and a Process.
List some java keywords sun like c, c + + keywords?
Define iterator and methods in iterator?
Mention some interfaces implemented by linked list in java.