title: Index out of bounds exception trying to create ArrayList with 1-based indices
body: <p>So up until this point I've just used <code>points.add(new Point(x,y))</code> to add points to my <code>ArrayList</code>. However, I found out that I need the first point to be in index=1 in order to make it possible to multiply the number for each step. So I tried setting the <code>counter</code> from <code>0</code> to <code>1</code>, and as expected I knew I would get a error because of the range, but I've tried changing up the condition within the while-loop, but nothing seems to work. </p>
  
  <p>Here's my code:</p>
  
  <pre><code>ArrayList&lt;Point&gt; points = new ArrayList&lt;&gt;();
  int counter = 1;
  int nPoints = 12;
  while (counter &lt;= nPoints) {
      x = (int) (centerX + r * Math.cos(start));
      y = (int) (centerY + r * Math.sin(start));
  
      points.set(counter, (new Point(x, y)));
      //points.add(new Point(x,y));
  
      counter++;
  }
  </code></pre>
  
  <p>This is the error that I am getting:</p>
  
  <pre><code>Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 0   
      at java.util.ArrayList.rangeCheck(Unknown Source)   
      at java.util.ArrayList.set(Unknown Source)
  </code></pre>
  
  <p>I've deleted much of the code that isn't relevant for this problem in order to make it easier to read.</p>
  
  <p><strong>Edit:</strong></p>
  
  <pre><code> public void paintComponent(Graphics g) {
              super.paintComponent(g);
              Graphics2D g2d = (Graphics2D) g;
              a = getWidth() /2;
              b = getHeight() /2;
              g2d.setColor(Color.RED);
  
              //draw cirle
              g2d.drawOval(a-r, b-r, 2*r, 2*r);
  
              //draw lines
              for (int  i= 1; i &lt; points.size();i ++) {
                  g2d.drawLine(points.get(i).x, points.get(i).y, points.get(i+1).x, points.get(i+1).y);
  
              }
  
             g2d.dispose();
          }
  </code></pre>
  
  <p>I've created a circle in which I'm trying to draw lines between points along the circumference. Here I want the 1st point to connect to 2, 2 to 4, 3 to 6, 4 to 8 and so on... So the pattern here is is that it is multiplied by 2 for each time. So my initial thought was that I could use the <code>i</code> inside the <code>for</code>-loop to multiply by 2 each time. But since I have my first point in i=0 inside the ArrayList, I am having trouble. </p>