How do I initialize a two-dimensional List statically?

前端 未结 3 651
孤街浪徒
孤街浪徒 2021-02-05 09:39

How can I initialize a multidimensional List statically?

This works:

List> list = new ArrayList>();
<         


        
3条回答
  •  面向向阳花
    2021-02-05 10:08

    You can do it this way:

    import static java.util.Arrays.*;
    

    ...

    List> list = asList(
        asList( 1, 2, 3 ),
        asList( 4, 5, 6 ),
        asList( 6, 7, 8 ) );
    

提交回复
热议问题