Hi,
Im new to java and would appreciate some help.

I have declared the following ArrayList moves = new ArrayList();
I have then populated the arraylist and would lik to make it availble as an array now.

How can I do this?

I have tried this but gives error
int[] moves2 = moves.ToArray() ;

This is my completet code, its trying to find legal moves then put them all into and array and return them. If you see anything else about my code that needs adjusting, please tell.


public int[] find_moves(){

ArrayList moves = new ArrayList();

for(int i=0; i<=31; i++){
System.out.println("board["+i+"] = "+board[i]);}

for(int i=1; i<=4; i++){
if (board[i]==1 && board[i+5]==0){
moves.add(+i+" "+ (i+5)); //System.out.println((i+1)+ "-"+ (i+6));
}
if (board[i]==1 && board[i+4]==0){
moves.add(+i+ "-"+ (i+4));}
}

for(int i=5; i<=8; i++){
if (board[i]==1 && board[i+4]==0){
moves.add(+i+ "-"+ (i+4));
}
if (board[i]==1 && board[i+3]==0){
moves.add(+i+ "-"+ (i+3));}
}

for(int i=9; i<=12; i++){
if (board[i]==1 && board[i+5]==0){
moves.add(+i+ "-"+ (i+5));
}
if (board[i]==1 && board[i+4]==0){
moves.add(+i+ "-"+ (i+4));}
}

for(int i=13; i<=16; i++){
if (board[i]==1 && board[i+4]==0){
moves.add(+i+ "-"+ (i+4));
}
if (board[i]==1 && board[i+3]==0){
moves.add(+i+ "-"+ (i+3));}
}

for(int i=17; i<=20; i++){
if (board[i]==1 && board[i+5]==0){
moves.add(+i+ "-"+ (i+5));
}
if (board[i]==1 && board[i+4]==0){
moves.add(+i+ "-"+ (i+4));}
}

for(int i=21; i<=24; i++){
if (board[i]==1 && board[i+4]==0){
moves.add(+i+ "-"+ (i+4));
}
if (board[i]==1 && board[i+3]==0){
moves.add(+i+ "-"+ (i+3));}
}

System.out.println(moves);
int[] moves2 = moves.ToArray() ;
return null;
}