Returns a new list containing the objects from start
inclusive to end
exclusive.
List<String> colors = ['red', 'green', 'blue', 'orange', 'pink']; colors.sublist(1, 3); // ['green', 'blue']
If end
is omitted, the length of this
is used.
colors.sublist(1); // ['green', 'blue', 'orange', 'pink']
An error occurs if start
is outside the range 0
.. length
or if end
is outside the range start
.. length
.
List<E> sublist(int start, [int end]) { int listLength = this.length; if (end == null) end = listLength; RangeError.checkValidRange(start, end, listLength); int length = end - start; List<E> result = <E>[]..length = length; for (int i = 0; i < length; i++) { result[i] = this[start + i]; } return result; }
© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/2.0.0/dart-collection/ListMixin/sublist.html