I'm still fairly new to Java and have recently started dabbling a bit with ArrayList and LinkedList. While programming a simple lottery-algorithm, I have encountered a problem I don't quite understand. 

Here's my code:

```
import java.util.*;

public class Millionaire 
{
    public static void main(String[] args) 
    {
        ArrayList<Integer> lottery = new ArrayList<Integer>();
        Random draw = new Random();

        for (int i = 0; i < 6; i++) 
        {
            lottery.add(draw.nextInt(50));
        }

        for (int m : lottery)
        {
            System.out.println(lottery.get(m));
        }
    }
}

```

Compiling goes without a hitch, but running the program pretty much always causes an OutOfBoundsExeption. It seems that the printing loop tries to use the content of the Arraylist as the indexes it tries to access, so that any entry larger than 6 causes the program to crash. Could anybody help my understand why it does that?