what this program prints the wrong reutls : <p>What I am trying to do is:</p>

<p>I have a list of values, and I want to list each three of them. For example:</p>

<p>I have: </p>

<pre><code>"one", "two", "three", "four", "five"
</code></pre>

<p>And I want to print the following:</p>

<pre><code>one two three
one two four
one four five
two three four
two three five
and so on
</code></pre>

<p>You got the point, I want every three values (not in order off course)</p>

<p>What I did is:</p>

<pre><code>import java.util.*;

public class Solution {
    public static void main(String args[]) {
        String[] people = new String[] { "one", "two", "three", "four",
                "five" };
        Solution s = new Solution();
        s.solve(people, 3, new LinkedList&lt;&gt;(), 0);
    }

    public void solve(String[] people, int n, List&lt;String&gt; data, int i) {
        if (data.size() == n) {
            System.out.println(data.toString());

        } else if (i &lt; people.length) {
            String value = people[i];
            solve(people, n, data, i + 1);
            data.add(value);
            solve(people, n, data, i + 1);
        }
    }
}
</code></pre>

<p>You can run it:</p>

<p>My problem is that it prints:</p>

<blockquote>
  <p>[five, four, five]</p>
</blockquote>

<p>Which is obviously wrong, how can It print two same values? In my code, I add the value once and I don't add it another time</p>

<p>Could you help?</p>
