title: Converting array to list in Java
body: <p>How do I convert an array to a list in Java?</p>
  <p>I used the <code>Arrays.asList()</code> but the behavior (and signature) somehow changed from Java SE <a href="http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-142docs-2045554.html" rel="noreferrer">1.4.2</a> (docs now in archive) to <a href="https://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#asList-T...-" rel="noreferrer">8</a> and most snippets I found on the web use the 1.4.2 behaviour.</p>
  <p>For example:</p>
  <pre><code>int[] numbers = new int[] { 1, 2, 3 };
  Arrays.asList(numbers)
  </code></pre>
  <ul>
  <li>on 1.4.2 returns a list containing the elements 1, 2, 3</li>
  <li>on 1.5.0+ returns a list containing the array 'numbers'</li>
  </ul>
  <p>In many cases it should be easy to detect, but sometimes it can slip unnoticed:</p>
  <pre><code>Assert.assertTrue(Arrays.asList(numbers).indexOf(4) == -1);
  </code></pre>