i have array. each element of array, want store multiple integers. know in c can make array of integer pointers, , use pointer make list.
in java, can make array of object 'a', has list of integers. why can't this
list<integer>[] arr = new arraylist<integer>[]();
i get:
type mismatch: cannot convert arraylist list[]
you typically want avoid mixing collections , arrays reason; array covariant (that is, integer[]
is-an object[]
), collections (and generics in general) invariant (that is, list<integer>
not list<object>
).
you can create list of lists instead, ensure type safety , around issue of creating generic array:
list<list<integer>> intnestedlist = new arraylist<>();