Solved

String buffer

Posted on 2003-12-11
8
357 Views
Last Modified: 2010-03-31
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
Comment
Question by:applekanna
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 25 total points
Comment Utility
That won't compile at the moment

>>return buff.toString      

should be

return buff.toString();      

0
 
LVL 92

Accepted Solution

by:
objects earned 25 total points
Comment Utility
they both should return the same.
0
 

Expert Comment

by:badprogrammer
Comment Utility
The above code wont compile
because >>> return buff.toString <<< should actually be buff.toString()
and yeah they both should give the same output.
0
 

Expert Comment

by:badprogrammer
Comment Utility
Sorry it should be return buff.toString().
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 3

Author Comment

by:applekanna
Comment Utility
Sorry but that was a typo there .....
0
 
LVL 3

Author Comment

by:applekanna
Comment Utility
got it I called it just as

MyObject.toString();

Should have encapsulated it in a System.out.

Thx for ur help
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
8-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now