title: Passing a parameter versus returning it from function
body: <p>As it might be clear from the title which approach should we prefer? </p>
  
  <p>Intention is to pass a few method parameters and get something as output. We can pass another parameter and method will update it and method need not to return anything now, method will just update output variable and it will be reflected to the caller.</p>
  
  <p>I am just trying to frame the question through this example.</p>
  
  <pre><code>List&lt;String&gt; result = new ArrayList&lt;String&gt;();
  
  for (int i = 0; i &lt; SOME_NUMBER_N; i++) {
      fun(SOME_COLLECTION.get(i), result);
  }
  
  // in some other class
  public void fun(String s, List&lt;String&gt; result) {
      // populates result
  }
  </code></pre>
  
  <p>versus</p>
  
  <pre><code>List&lt;String&gt; result = new ArrayList&lt;String&gt;();
  
  for (int i = 0; i &lt; SOME_NUMBER_N; i++) {
      List&lt;String&gt; subResult = fun(SOME_COLLECTION.get(i));
      // merges subResult into result
      mergeLists(result, subResult);
  }
  
  // in some other class
  public List&lt;String&gt; fun(String s) {
      List&lt;String&gt; res = new ArrayList&lt;String&gt;();
      // some processing to populate res
      return res;
  }
  </code></pre>
  
  <p>I understand that one passes the reference and another doesn't.</p>
  
  <p>Which one should we prefer (in different situations) and why?</p>
  
  <p><strong>Update</strong>: Consider it only for mutable objects.</p>