Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: -1163179553, Size: 0
<p>I am new to java environment, i m developing code for playing cards in java application.I am adding 52 elements in the arraylist for different suit.When adding items in the list i m getting index bound exception,but item is able to add in the list.</p>

<pre><code>while (totalcards &lt; 4) {
  for (int i = 1; i &lt;= 13; i++) {
    switch(i) {
       case 1:
          b.add(new Cards(0,'F','A',suits[totalcards]));
          System.out.println(i);
          break;
       case 11:
          b.add(new Cards(0,'F','K',suits[totalcards]));
          System.out.println(i);
          break;
       case 12:
          b.add(new Cards(0,'F','Q',suits[totalcards]));
          System.out.println(i);
          break;
       case 13:
          b.add(new Cards(0,'F','J',suits[totalcards]));
          System.out.println(i);
          break;
       default:
          b.add(new Cards(i,'F','J',suits[totalcards]));
          System.out.println(i);
          break;
    }
  }
  totalcards++;
}
</code></pre>

<p>Output:</p>

<pre><code>1
2
3
4
5
6
7
8
9
10
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: -1163179553, Size: 0
11
12
13
1
2
3
4
5
6
7
8
9
10
    at java.util.ArrayList.rangeCheckForAdd(ArrayList.java:612)
11
    at java.util.ArrayList.add(ArrayList.java:426)
    at gambler.Gambler.main(Gambler.java:92)
12
13
1
2
3
4
5
6
7
8
9
10
11
12
13
1
2
3
4
5
6
7
8
9
10
11
12
13
</code></pre>

<p>tried a lot but i didnt get any breakthrough..I would be glad if someone suggest me actual problem</p>
