To create a list of empty lists in Java, you can initialize a List of Lists with empty ArrayList elements.
In this example,
java.util.List
and java.util.ArrayList
classes for List and ArrayList functionality.emptyList
to hold empty Lists.import java.util.ArrayList;
import java.util.List;
class Main {
public static void main(String[] args) {
List<List<String>> emptyList = new ArrayList<>();
emptyList.add(new ArrayList<>());
emptyList.add(new ArrayList<>());
emptyList.add(new ArrayList<>());
System.out.println(emptyList);
}
}
[[], [], []]
In this tutorial, we learned How to create a List of Empty Lists in Java language with well detailed examples.