when we create a String variable as String str="pawan"; Stirng str=new Sring("pawan"); what is difference between both .
Pawan Sinha
Greenhorn
Joined: Jan 16, 2001
Posts: 10
posted
0
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
Sheriff
Joined: Jan 07, 1999
Posts: 6913
posted
0
This is not a servlet question, so I've moved it to "Java in General, Beginner"
"JavaRanch, where the deer and the Certified play" - David O'Meara
sona gold
Ranch Hand
Joined: Feb 14, 2001
Posts: 234
posted
0
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: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.