title: Can I assign Java values from an ArrayList to different variables without hardcoding the size?
body: <p>I have an ArrayList, and we'll say it can be at most size 5. I want to assign the first element to var1, the second to var2, the third to var3, etc. </p>
  
  <p>However, sometimes the ArrayList will have less than 5 items, in which case I won't be assigning some variables a value.</p>
  
  <p>So my question is, is there a better way to do this other than:</p>
  
  <pre><code>if (myArrayList.size() &gt; 0)
      var1 = myArrayList.get(0);
  if (myArrayList.size() &gt; 1)
      var2 = myArrayList.get(1);
  if (myArrayList.size() &gt; 2)
      var3 = myArrayList.get(2);
  if (myArrayList.size() &gt; 3)
      var4 = myArrayList.get(3);
  if (myArrayList.size() &gt; 4)
      var5 = myArrayList.get(4);
  </code></pre>