Creating a grid with a 2d array
<p>I am currently working on creating the game Snake. I had the idea of creating a basic 2-dimensional arraylist so I can create cells but I can't find any form of help on creating that 2d arraylist to store the x and y values of each of the cells. I need help on how to create that 2d arraylist and how to use it.</p>

<p>Snake.java</p>

<pre><code>package snake;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.List;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JPanel;


public class Snake extends JPanel implements KeyListener {

private static final long serialVersionUID = 1L;
static final int BOX_WIDTH = 600;
static final int BOX_HEIGHT = BOX_WIDTH;
int UPDATE_RATE = 300;
ArrayList&lt;Cell&gt; CellList = new ArrayList&lt;Cell&gt;();



//ode below????
//2d arrayList

ArrayList[][] Cell = new ArrayList[10][10];


public Snake() {

    setPreferredSize(new Dimension(BOX_WIDTH, BOX_HEIGHT));

    /*for (int i = 0; i &lt; 5; i++) {

        for (int j = 0; j &lt; 5; j++) {
            CellList.add(new Cell(i,j));
        }
    } */



    Thread gameThread = new Thread() {

        public void run() {
            while(true){
                repaint();
                try {Thread.sleep(1000/UPDATE_RATE);}
                catch (InterruptedException ex) {}
            }
        }
    };
    gameThread.start();
}
public static void main(String[] args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            JFrame frame = new JFrame("SNEK");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            Snake snake = new Snake();
            frame.setContentPane(snake);
            frame.setSize(BOX_WIDTH, BOX_HEIGHT);
            frame.pack();
            frame.addKeyListener(snake);
            frame.setVisible(true);
        }
    }); 
}

public void paintComponent(Graphics g) {
    g.setColor(Color.pink);
    g.fillRect(0, 0, BOX_WIDTH, BOX_HEIGHT);

    /*for (int i = 0; i &lt; 5; i++) {
        for (int j = 0; j &lt; 5; j++) {
                CellList.get(i,j).draw(g);

        }
    } */
}

@Override
public void keyPressed(KeyEvent arg0) {

}
@Override
public void keyReleased(KeyEvent arg0) {

}
@Override
public void keyTyped(KeyEvent arg0) {}



}
</code></pre>

<p>Cell.java</p>

<pre><code>package snake;

import java.awt.Color;
import java.awt.Graphics;

public class Cell extends Snake{

private static final long serialVersionUID = 1L;
final int CELL_HEIGHT = 10;
final int CELL_WIDTH = 10;

int status = 0;
int xPos;
int yPos;

public Cell(int x, int y) {

    xPos = x * 120;
    yPos = y * 120; 
}

public void draw(Graphics g) {
    g.setColor(Color.magenta);
    g.fillRect(xPos, yPos, CELL_WIDTH, CELL_HEIGHT);
}

}
</code></pre>