Java; saving array of arrays into collection -


so have data

 { { 1,  3, 5, 3, 1 },    { 3,  5, 6, 5, 1 },    { 7,  2, 3, 5, 0 },    { 12, 1, 5, 3, 0 },    { 20, 6, 3, 6, 1 },     { 20, 7, 4, 7, 1 } } 

and want save kind of collection, list or set. if collection named list,if type list[0][3] reffer int 4. tried

arraylist<int[]> mynumberlist = new arraylist<int[]>(); 

but have trouble putting data list

you make integer[][] , create list<list<integer>>. like,

integer[][] arr = { { 1, 3, 5, 3, 1 }, { 3, 5, 6, 5, 1 },          { 7, 2, 3, 5, 0 }, { 12, 1, 5, 3, 0 }, { 20, 6, 3, 6, 1 },          { 20, 7, 4, 7, 1 } }; system.out.println(arrays.deeptostring(arr)); list<list<integer>> al = new arraylist<>(); (integer[] inarr : arr) {     al.add(arrays.aslist(inarr)); } system.out.println(al); 

which outputs (formatted post)

[[1, 3, 5, 3, 1], [3, 5, 6, 5, 1], [7, 2, 3, 5, 0],                    [12, 1, 5, 3, 0], [20, 6, 3, 6, 1], [20, 7, 4, 7, 1]] [[1, 3, 5, 3, 1], [3, 5, 6, 5, 1], [7, 2, 3, 5, 0],                    [12, 1, 5, 3, 0], [20, 6, 3, 6, 1], [20, 7, 4, 7, 1]] 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -