How can I initialize List
in Java? >
I know List
is an interface and I can use ArrayList
or Linked
Use
List<List<Integer>> list = new ArrayList<List<Integer>>();
or since Java 1.7
List<List<Integer>> list = new ArrayList<>();
You can define it as List<List<Integer>> list = new LinkedList();
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>
.