Answers for "java initialize two dimensional list"

0

initialize multidimensional list in java

import java.util.Arrays.*;

List<List<T>> items = new ArrayList<>(Arrays.asList(
  	Arrays.asList(T ...items),
    Arrays.asList(T ...items1),
    Arrays.asList(T ...items2)
));


//for string type :
List<List<String>> items = new ArrayList<>(Arrays.asList(
  	Arrays.asList("a", "b", "c"),
    Arrays.asList("d", "e", "f"),
    Arrays.asList("g", "h", "i")
));

System.out.println("Output : " + items.toString());
//Output : [ [a, b, c], [d, e, f], [g, h, i] ]

//Another answer from stackoverflow suggests a way without using built-in as:List method
// Link : https://stackoverflow.com/a/6233024
Posted by: Guest on August-21-2021

Code answers related to "java initialize two dimensional list"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language