void main() {
List listOfLists = [['a', 'b', 'c'], [], ['d', 'e'], [], [], ['f', 'g', 'h'], [], []];
List result = listOfLists.expand((x) => x).toList();
print(result);
}
Output
[a, b, c, d, e, f, g, h]
A Dart List is a collection of elements that can be used to store and access data using the index. The List is a mutable collection means you can use add or remove items from it.
We are using here List.expand() function to flatten a list of lists and remove empty lists for it.
0 Comments