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 obj in heap and adds entry in literal pool
String s1 = s.intern(); // fetches the existing object's value.
System.out.println(s1);
@Ravi
String hashCode has generic mechanism as below.
s[0]*31^n-1 + s[1]*31^n-2 ....+s[n-1]
n - length of string
s[0] - ascii value of the character
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
what are synchronized methods and synchronized statements? : Java thread
What are different ways of object creation in java ?
What is broken and continue statement?
What is the private method modifier?
How do you allocate memory to object?
I want to re-reach and use an object once it has been garbage collected. How it's possible?
What is remote method invocation (rmi)?
Can each java object keep track of all the threads that want to exclusively access it?
What is style and indentation?
what is enumset?
Explain the difference between treeset and treemap in java?
What is a classloader in java?
How will you get the platform dependent values like line separator, path separator, etc., ?
How many arguments can a method have java?
Is it possible to compare various strings with the help of == operator? What are the risks involved?