• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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);
 
It is no measure of health to be well adjusted to a profoundly sick society. -Krishnamurti Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic