when we create a String variable as String str="pawan"; Stirng str=new Sring("pawan"); what is difference between both .
Joined: Jan 16, 2001
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.
Joined: Jan 07, 1999
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
Joined: Feb 14, 2001
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