Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java" Watch "java" New topic


pawan sharma

Joined: Feb 12, 2001
Posts: 7
when we create a String variable as
String str="pawan";
Stirng str=new Sring("pawan");
what is difference between both .
Pawan Sinha

Joined: Jan 16, 2001
Posts: 10
string str= new String("Pawan") creates a new memory space for string str, so if u will equate the two string variables declared as in yr query, the result will be false as these two string variable are having diffrent reference.
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
This is not a servlet question, so I've moved it to "Java in General, Beginner"

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
This thread has an excellant explaination of the difference between the literal and the object.

"JavaRanch, where the deer and the Certified play" - David O'Meara
sona gold
Ranch Hand

Joined: Feb 14, 2001
Posts: 234
String str = "pawn"
stores the constant pawn in the variable str
String str = new String(pawn)
creates a new string object and stores the refernce to that object in str and pawn is passed to the constructor of that object

sona<br />SCJP
I agree. Here's the link:
subject: java
It's not a secret anymore!