• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why two types of String creation.  RSS feed

 
Amitt Thakkarr
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can any one tell me why Java provides two types of string Creation?

1. String s = "abc";
2. String s1 = new String("abc");

1. String s = "abc"; --- Will create the string object or literal. But why Java provides this way of creating the String.
This way of creating an Object is only with String class not with any other Class.

Thanks,
Regards,
Amit
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strangely enough that question (or one very similar to it) was asked earlier today. There are some useful links from that thread that should explain more.
 
Mohamed Sanaulla
Bartender
Posts: 3179
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And that is why Please SearchFirst
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch

There are lots of ways to create a String, not only two.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!