File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: String Q