0

If we create same string 100 times using new operator as shown below, how many objects will be created and if 100 objects will be created, it soulds like creating same string 100 times is not best and it looks JAVA inefficiently handling string object creation that is creating 100 objects for same string?

Please help me to understand. What is happening in reality?

String obj1 = new String("Hello");
String obj2 = new String("Hello");
String obj3 = new String("Hello");
................
................
String obj99 = new String("Hello");
String obj100 = new String("Hello");
mike
  • 377
  • 1
  • 9
  • 22
  • 1
    This question was answered ∞ + 6 times, exactly. – Maroun Sep 02 '14 at 11:54
  • This question must have been asked a thousand times here. Possible [duplicate](http://stackoverflow.com/q/5192574/697630). – Edwin Dalorzo Sep 02 '14 at 11:54
  • If you have a question that is not answered in the duplicate *nor* anywhere else, edit your post to clarify the confusion. If it does answer everything, take it as an indication to search a bit longer next time. – Jeroen Vannevel Sep 02 '14 at 11:56
  • See for instance [Questions about Java's String pool](http://stackoverflow.com/questions/1881922/questions-about-javas-string-pool) – ratiaris Sep 02 '14 at 11:59

0 Answers0