Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 401
  • Last Modified:

String buffer

Hi I have the followig method
      public String toString()
      {
        StringBuffer buff = new StringBuffer();
        buff.append("This is a test message");
        return buff.toString      
      }

This returns  "" basically nothing
but if I use
                 return new String(buff.toString());

This returns the required result.

Cant understand :(

0
applekanna
Asked:
applekanna
  • 2
  • 2
  • 2
  • +1
2 Solutions
 
CEHJCommented:
That won't compile at the moment

>>return buff.toString      

should be

return buff.toString();      

0
 
objectsCommented:
they both should return the same.
0
 
badprogrammerCommented:
The above code wont compile
because >>> return buff.toString <<< should actually be buff.toString()
and yeah they both should give the same output.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
badprogrammerCommented:
Sorry it should be return buff.toString().
0
 
applekannaAuthor Commented:
Sorry but that was a typo there .....
0
 
applekannaAuthor Commented:
got it I called it just as

MyObject.toString();

Should have encapsulated it in a System.out.

Thx for ur help
0
 
objectsCommented:
0
 
CEHJCommented:
8-)
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now