split method
- int count
Splits the list into multiple sublists of the specified count
.
The original list is divided into sublists of size count
,
except for the last sublist which may have a smaller size if the
length of the original list is not divisible by count
.
Example:
var myList = [1, 2, 3, 4, 5, 6, 7, 8, 9];
var result = myList.split(3);
print(result); // [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Returns a new list containing the sublists.
Implementation
List<List<T>> split(int count) {
var l = toList();
var r = <List<T>>[];
for (var i = 0; i < l.length; i += count) {
r.add(l.sublist(i, i + count));
}
return r;
}