• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String object creation

 
Prathima gaitonde
Ranch Hand
Posts: 130
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are all String objects created in String pool are they never be able to created on heap/memory?

Example:

String s="Hello";//Gets created in string pool

String s=new String("Hello");// I think this gets created in heap.

Please correct me if I am wrong.

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This article about strings will be very helpful to you (and will provide an answer to your question).
 
Prathima gaitonde
Ranch Hand
Posts: 130
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh!!! many thanks @Roel De Nijs, It solved my query, not only on String literals and objects but also on garbage collection of Strings.

Thanking you once again
With respect
Prathima Gaitonde
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic