HOW to port "compact" Python to "compact" Java?
<p>A friend is doing an online Scala course and shared this. </p>

<pre><code># Write a recursive function that counts how many different ways you can make
# change for an amount, given a list of coin denominations. For example, there
# are 3 ways to give change for 4 if you have coins with denomiation 1 and 2:
# 1+1+1+1, 1+1+2, 2+2.
</code></pre>

<hr>

<h2>If you are attending and still working on a solution, don't read this!</h2>

<p><strong>(disclaimer: even if my Python solution may be wrong, I don't want to influence your thinking if you are on the course, one way or the other! I guess it is the <em>thinking</em> that goes into it that yields learning, not just the "solving"...)</strong></p>

<hr>

<p>That aside...</p>

<p>I thought I'd have a go at it in Python as I don't have the Scala chops for it (I am not on the course myself, just interested in learning Python and Java and welcome "drills" to practice on).</p>

<p>Here's my solution, which I'd like to port to Java using as compact a notation as possible:</p>

<hr>

<pre><code>def show_change(money, coins, total, combo):
  if total == money:
    print combo, '=', money
    return 1
  if total &gt; money or len(coins) == 0:
    return 0
  c = coins[0]
  return (show_change(money, coins, total + c, combo + [c]) +
    show_change(money, coins[1:], total, combo))

def make_change(money, coins):
  if money == 0 or len(coins) == 0:
    return 0
  return show_change(money, list(set(coins)), 0, [])

def main():
  print make_change(4, [2, 1])

if __name__ == '__main__':
  main()
</code></pre>

<hr>

<h2>Question</h2>

<ul>
<li>How compact can I make the above in Java, allowing the use of libraries external to the JDK if they help?</li>
</ul>

<p>I tried doing the porting myself but it was getting <em>very</em> verbose and I thought the usual <em>"there must be a better way of doing this"</em>!</p>

<p>Here my attempt:</p>

<hr>

<pre><code>import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.Lists;
import com.google.common.primitives.Ints;
public class MakeChange {
  static int makeChange(int money, int[] coins) {
    if (money == 0 || coins.length == 0) {
      return 0;
    }
    return showChange(money, Ints.asList(coins), 0, new ArrayList&lt;Integer&gt;());
  }
  static int showChange(int money, List&lt;Integer&gt; coins, int total,
      List&lt;Integer&gt; combo) {
    if (total == money) {
      System.out.printf("%s = %d%n", combo, total);
      return 1;
    }
    if (total &gt; money || coins.isEmpty()) {
      return 0;
    }
    int c = coins.get(0);
    List&lt;Integer&gt; comboWithC = Lists.newArrayList(combo);
    comboWithC.add(c);
    return (showChange(money, coins, total + c, comboWithC) + showChange(money,
        coins.subList(1, coins.size()), total, combo));
  }
  public static void main(String[] args) {
    System.out.println(makeChange(4, new int[] { 1, 2 }));
  }
}
</code></pre>

<hr>

<p>Specifically, what I dislike a lot is having to do the stuff below just to pass a copy of the list with an element appended to it:</p>

<pre><code>    List&lt;Integer&gt; comboWithC = Lists.newArrayList(combo);
    comboWithC.add(c);
</code></pre>

<p>Please show me how compact and readable Java can be. I am still a beginner in both languages...</p>
