wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String Q Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String Q" Watch "String Q" New topic
Author

String Q

kevin goon
Ranch Hand

Joined: Jun 12, 2001
Posts: 62
public class b{
public static void main(String args[]){
StringBuffer sb1 = new StringBuffer("Amit");
StringBuffer sb2= new StringBuffer("Amit");
String ss1 = "Amit";
System.out.println(sb1==sb2);
System.out.println(sb1.equals(sb2));
System.out.println(sb1.equals(ss1));
System.out.println("Poddar".substring(3));
}
}
What is the output?? and why??
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
public class b{
public static void main(String args[]){
StringBuffer sb1 = new StringBuffer("Amit");
StringBuffer sb2= new StringBuffer("Amit");
String ss1 = "Amit";
System.out.println(sb1==sb2);
System.out.println(sb1.equals(sb2));
System.out.println(sb1.equals(ss1));
System.out.println("Poddar".substring(3));
}
}

false
The 2 StringBuffer objects do not point to the same object.
false
StringBuffer inherits the Object classes equals() method. So it is not doing the same thing that String equals() method does.
false
See above answer.
dar
Poddar - 0 based so 3 starts at the second d.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String Q
 
Similar Threads
string buffer
Equal(),==
String and StringBuffer
string(buffer) comparision...
equals with stringbuffer