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

Can a final method be overloaded?

511


How is string immutable in java?

545


How does map works in java?

519


Explain about the dynamic behavior of core java?

637


Explain the difference between comparator and comparable in java?

487






Why is stringbuffer called mutable?

567


What is meant by attribute?

595


What is the class in java?

565


What is string :: npos?

583


What are unchecked exceptions in java?

615


Can we create a constructor in abstract class?

575


What are the 6 mandatory procedures for iso 9001?

532


What is a class reference?

555


What is a constructor, constructor overloading in java?

531


How java is similar to c?

588