title: Collecting errors in a Java method, empty ArrayList vs. LinkedList
body: <p>I seem to create these two kind of methods occasionally:</p>
  
  <pre><code>// return null on errors, and append errors to 2nd param, otherwise return result
  String fetchSomething(String parameter, List&lt;String&gt; errorMessagesOut);
  
  // return empty list or null on no errors, otherwise list of errors
  List&lt;String&gt; verifySomething(String parameter);
  </code></pre>
  
  <p>And then the code which calls these will join the error list with appropriate separator (such as simple comma, newline, HTML tags...), usually using Apache Commons <code>Stringutils.join</code> method. And in normal case there's no error, and list will be empty.</p>
  
  <p>So, I started wondering about these two questions:</p>
  
  <ol>
  <li><p>Do you see a problem with returning error message strings as list? If so, what is better alternative? (Not exceptions, that would be thrown by code which calls these methods, when that is wanted.)</p></li>
  <li><p>Is <code>new LinkedList()</code> or <code>new ArrayList(0)</code> or <code>new ArrayList()</code> better for list which is <em>expected</em> to remain empty, and which should normally have only sequential iterator access when it is not empty?</p></li>
  </ol>
  
  <hr>
  
  <p>EDIT: Example use case:</p>
  
  <pre><code>List&lt;String&gt; verifyParameters(JSONObject params) {
      List&lt;String&gt; ret = new ArrayList&lt;String&gt;(0);
  
      if (!verifyKey(params.get("key"))) 
          ret.add("Invalid key: " + key);
  
      if (!verifyAccess(params.get("user"), params.get("pass"))) 
          ret.add("Authentication error");
  
     return ret;
  }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>List&lt;String&gt; errors = verifyParameters(params);
  if (!errors.isEmpty()) {
  
      connection.sendErrorListMessage(errors);
      logger.warn(StringUtils.join(errors, ", "));
      controlPanel.show("Errors: \n- " + StringUtils.join(errors, "\n- ") + '\n');
      throw new AbortException("invalid params); // or maybe return false/null;
  }
  // proceed with valid params
  </code></pre>
  
  <p>Usually handling of error list would not have all of those, it just tries to illustrate the point that error list is a list of messages meant for humans to see, independent of how it will be shown, and also not related to/useful for handling different errors differently.</p>