 <p>The <code>maxElements</code> could be a limit for the list. You can use <code>x.size() &gt; 0</code> check if you want <code>x.get(0)</code>.</p> <pre><code>ArrayList&lt;Points&gt; x = new ArrayList&lt;&gt;(); for (int i = 0; i &lt; maxElements; i++) { x.add(new Point(0, 0)); } Points p; if (x.size() &gt; 0) p = x.get(0); </code></pre>