Solved

String buffer

Posted on 2003-12-11
8
371 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
ID: 9925363
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
ID: 9925384
they both should return the same.
0
 

Expert Comment

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

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Expert Comment

by:badprogrammer
ID: 9925562
Sorry it should be return buff.toString().
0
 
LVL 3

Author Comment

by:applekanna
ID: 9925608
Sorry but that was a typo there .....
0
 
LVL 3

Author Comment

by:applekanna
ID: 9925645
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
ID: 9925656
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9928320
8-)
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to see all occupied ports on windows 10 laptop 15 76
java imports not found 4 27
Java basic valueOf question 1 29
Java Eclipse Loop 3 21
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

829 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