This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Difference between following two String Statements Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Difference between following two String Statements" Watch "Difference between following two String Statements" New topic
Author

Difference between following two String Statements

Praveen palukuri
Ranch Hand

Joined: Feb 10, 2005
Posts: 65
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

Joined: Jul 08, 2003
Posts: 24081
    
  15

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!


[Jess in Action][AskingGoodQuestions]
Naveen Vooka
Greenhorn

Joined: Oct 13, 2004
Posts: 25
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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Difference between following two String Statements
 
Similar Threads
string object
Difference between the two types of tostring methods?
String Intern
About String
Difference Between the String s = "String "; and String s = new String("String");