• Post Reply Bookmark Topic Watch Topic
  • New Topic

About "StringBuffer"  RSS feed

 
Paul Lin
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two questions about "StringBuffer"...
1)Can the StringBuffer override the equals(Object obj) method of the origin Object?
2)Should we transform StringBuffer into String when comparing two StringBuffers?
Thanks !
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,
Welcome to JavaRanch!
1) Surprisingly enough, StringBuffer does not override equals(), so no two StringBuffer objects are equal even if they contain the same characters.
2) StringBuffer contains no methods for comparing one StringBuffer to another. Your only two options are converting them to Strings, or writing a comparison method yourself which used StringBuffer.charAt() to compare them one character at a time.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!