• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

string buffer

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please check this code
class Test45
{
public static void main(String[] args)
{
String s1 = new String("ABC"), s2 = new String("ABC");
StringBuffer sb1 = new StringBuffer("ramesh");
StringBuffer sb2 = new StringBuffer("malli");
System.out.print(s1.equals(s2) + "," + sb1.equals(sb2) +","+ (sb1==sb2));
}

What's the answer for this . I think true,false,false.

My doubt is can't we ever compare StringBuffers How can we say two String Bufferes are equal,explain .
 
Ranch Hand
Posts: 481
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you are right

the answer is true , false , false

String buffer can never be equals because they dont override the equals method.
 
Karu Raj
Ranch Hand
Posts: 481
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also remember

If you try to code like this ... you will get compile error .
check out and try ..... because String and stringbuffer are of incompatible types.

System.out.print(s1==sb1);
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic