0

So I created two arrays and an arrayList. Depending on the value of game(0 or 1), I want my arrayList to have all the values of one of my arrays. Here's what I've been trying

int[] americanBoard = {0,28,9,26,30,11,7,20,32,17,5,22,34,15,3,24,36,13,1,00,27,10,25,29,12,8,19,31,18,6,21,33,16,4,23,35,14,2};
int[] europeanBoard = {0,32,15,19,4,21,2,25,17,34,6,27,13,36,11,30,8,23,10,5,24,16,33,1,20,14,31,9,22,18,29,7,28,12,35,3,26};
ArrayList<Integer[]> board = new ArrayList<Integer[]>();
(game>0? board.add(americanBoard): board.add(europeanBoard));

Thanks for helping!

1
  • This question has already been answered here Commented Feb 7, 2015 at 3:45

1 Answer 1

2

You can change your arrays type to Integer and then use the Arrays.asList method:

        Integer[] americanBoard = {0,28,9,26,30,11,7,20,32,17,5,22,34,15,3,24,36,13,1,00,27,10,25,29,12,8,19,31,18,6,21,33,16,4,23,35,14,2};
        Integer[] europeanBoard = {0,32,15,19,4,21,2,25,17,34,6,27,13,36,11,30,8,23,10,5,24,16,33,1,20,14,31,9,22,18,29,7,28,12,35,3,26};
        ArrayList<Integer> board = new ArrayList<Integer>(Arrays.asList((game>0? americanBoard: europeanBoard)));

You can find more info regarding that method in Javadocs:

Returns a fixed-size list backed by the specified array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.