I am working on writing a sudoku solver and I want the grid to be stored as an arraylist of arraylist of ints...each spot will have an arraylist of ints of all possible numbers (or the definite value).
ArrayList<ArrayList<int>> sudoku_board = new ArrayList <ArrayList<int>>();
Java is throwing me an error saying "dimensions expected after token" on the ints.
Generic type parameters require reference types, rather than primitive types. Use
List<ArrayList<Integer>> sudoku_board = new ArrayList <ArrayList<Integer>>();
Also when coding to an interface use the interface as the reference type, in this case List. Everything that appears within the generics should remain as the implementation type due to the non co-variance of generics.
From @assylias comment, a more generic type of list is
List<List<Integer>> list = new ArrayList<List<Integer>>();
This will allow for List implementations types other than ArrayList to be added should refactoring be necessary later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With