Initialize List> in Java

前端 未结 3 544
一个人的身影
一个人的身影 2021-01-31 00:09

How can I initialize List> in Java?

I know List is an interface and I can use ArrayList or Linked

相关标签:
3条回答
  • 2021-01-31 00:23

    Use

    List<List<Integer>> list = new ArrayList<List<Integer>>();
    

    or since Java 1.7

    List<List<Integer>> list = new ArrayList<>();
    
    0 讨论(0)
  • 2021-01-31 00:26

    You can define it as List<List<Integer>> list = new LinkedList();

    0 讨论(0)
  • 2021-01-31 00:33

    You can define it as List<List<Integer>> list = new ArrayList<List<Integer>>();.

    Then while defining the inner List you can take care of initialising it as ArrayList<Integer>.

    0 讨论(0)
提交回复
热议问题