wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes toString Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "toString" Watch "toString" New topic
Author

toString

Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 74
I'm trying to make a toString to display my stack but i'm getting incompatible types. its the method starting on 106.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11477
    
  16

should line 108 be



(missing the parens)


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 74
I sure do feel silly now thank you
Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 74
although When it prints out in gui it only prints out 1 item of the stack what I would like it to do is keep printing out the entire stack such as
4
3
2
n
t
So you can see every element in the stack, this is what i'm using in my gui to print it out at the moment.

outputStackTF.setText(myStack.toString());
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11477
    
  16

I've just barely skimmed your code, so i may not be correct. But it looks to me like in your public String toString() method, you are only calling the toString() method on the top element...therefore, it only prints what is in the top element.

What you would need to do is write some code that reads each element in the stack and calls IT'S toString() method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: toString