Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between following two String Statements

 
Praveen palukuri
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
can u give me exact difference between following 2 statements.

String str1 = "hai";
String str2 = new String("hello");
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first one refers to a String object which is created when the class is loaded. The second one creates a copy of an existing String object. The second one is a form you'll never see except on certification exams, or in code written by newbies who have learned Java by studying for those exams!
 
Naveen Vooka
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Praveen palukuri:
can u give me exact difference between following 2 statements.


http://www.javaworld.com/javaforums/showflat.php?Cat=2&Board=javabeginner&Number=22223&page=1&view=collapsed&sb=5&o=&fpart=1

--------------
Naveen Vooka
www.devsquare.com
DevSquare - Online Application Development
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic