title: How do I write a method which would work on both lists and arrays?
body: <p>I have a method which looks like this:</p>
  
  <pre><code>void foo (List&lt;String&gt; list, ...) {
    ...
    for (String s : list) { // this is the only place where `list` is used
      ...
    }
    ...
  }
  </code></pre>
  
  <p>the exact same code would work if I replace <code>List&lt;String&gt; list</code> with <code>String[] list</code>, however, to avoid spaghetti code, I keep the single method, and when I need to call it on an array <code>a</code>, I do it like this: <code>foo(Arrays.asList(a))</code>. </p>
  
  <p>I wonder if this is The Right Way.</p>
  
  <p>Specifically, </p>
  
  <ul>
  <li>What is the overhead of <code>Arrays.asList()</code>?</li>
  <li>Is there a way to write a method which would accept both arrays and lists, just like the <code>for</code> loop does?</li>
  </ul>
  
  <p>Thanks!</p>