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


Please Help Members By Posting Answers For Below Questions

what are synchronized methods and synchronized statements? : Java thread

764


What are different ways of object creation in java ?

763


What is broken and continue statement?

724


What is the private method modifier?

798


How do you allocate memory to object?

710


I want to re-reach and use an object once it has been garbage collected. How it's possible?

757


What is remote method invocation (rmi)?

803


Can each java object keep track of all the threads that want to exclusively access it?

739


What is style and indentation?

747


what is enumset?

784


Explain the difference between treeset and treemap in java?

737


What is a classloader in java?

723


How will you get the platform dependent values like line separator, path separator, etc., ?

781


How many arguments can a method have java?

784


Is it possible to compare various strings with the help of == operator? What are the risks involved?

827