aspose file tools*
The moose likes Beginning Java and the fly likes Recursion, with using Lists to store data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Recursion, with using Lists to store data" Watch "Recursion, with using Lists to store data" New topic
Author

Recursion, with using Lists to store data

mandlar suurla
Ranch Hand

Joined: Jun 11, 2008
Posts: 67

I am struggling with this problem for long time and i haven't found any simple solutions.

As you can see i have made simple list to store numbers from 0 to 4, but the problem it gets the stackOverFlowError.
The result should be list.get(0) = 0 ... and list.get(3) = 4

Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3613
    
  14

Hey there! Can you explain in your own words what the difference is between:

++counter;
and
counter++?

If you don't know the difference, look up what the difference is between prefix increment and postfix increment.

Take note that the correct words are "recursion" and "recursive", not "recrusion" and "recrusive".
mandlar suurla
Ranch Hand

Joined: Jun 11, 2008
Posts: 67

Stephan van Hulst wrote:Hey there! Can you explain in your own words what the difference is between:

++counter;
and
counter++?

If you don't know the difference, look up what the difference is between prefix increment and postfix increment.

Take note that the correct words are "recursion" and "recursive", not "recrusion" and "recrusive".

prefix increment, the statement value is increased first before use, but postfix increment takes value and then increases.

example
counter = 0;

if (++counter) -- the counter is increased first and then the boolean check if (1)

if (counter++) -- counter is increased after use in statement if (0) and then make +1

Am I right ? But the problem still lies in recursion.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3613
    
  14

[edit]

Actually no, there are no checks. The prefix operator first increases the variable, and then returns the value. The postfix operator increases the variable, but returns the value it was before the increment.
How could this affect your recursion?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Recursion, with using Lists to store data