简体   繁体   中英

How to Initialize 2d ArrayList with 0 in one line

How to Initialize all the element of 2d Array List in Java with 0 in single line of code without using for lop.

ArrayList of m rows and n columns.

How to initialise value of all the elements to 0 at the time of defining it.

Not sure what you meant by 2D ArrayList, but you returned type of List instead of ArrayList with help of below:

List<List<Integer>> a=Arrays.asList(Arrays.asList(0));

For normal arrays you can do something:

int[][] b=new int[1][2];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM