collections - ArrayList of ArrayList of ints in Java? -
i working on writing sudoku solver , want grid stored arraylist of arraylist of ints...each spot have arraylist of ints of possible numbers (or definite value).
arraylist<arraylist<int>> sudoku_board = new arraylist <arraylist<int>>(); java throwing me error saying "dimensions expected after token" on ints.
generic type parameters require reference types, rather primitive types. use
list<arraylist<integer>> sudoku_board = new arraylist <arraylist<integer>>(); also when coding interface use interface reference type, in case list. appears within generics should remain implementation type due non co-variance of generics.
from @assylias comment, more generic type of list is
list<list<integer>> list = new arraylist<list<integer>>(); this allow list implementations types other arraylist added should refactoring necessary later.
Comments
Post a Comment