Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

String object creation  RSS feed

 
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: 11077
173
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!