Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Write the algorithm to check the number non-leaf nodes in a tree.

1080


What is indexof?

992


Can we have multiple classes in a single file?

983


What is meant by vector class, dictionary class, hash table class, and property class?

1164


What is the difference between final, finally and finalize()?

1163


What is a arraylist in java?

1083


What is a string what operation can be performed out with the help of a string?

1054


How an object is serialized in java?

996


What is treeset in java collection?

977


What are the types of methods in java?

1125


How to implement a multithreaded applet?

2679


Explain the difference between a Thread and a Process.

1006


List some java keywords sun like c, c + + keywords?

1011


Define iterator and methods in iterator?

975


Mention some interfaces implemented by linked list in java.

1026