sublist method

IList<T> sublist(
  1. int start, [
  2. int? end
])

Returns a new list containing the elements between start and end.

The new list is a List<E> containing the elements of this list at positions greater than or equal to start and less than end in the same order as they occur in this list.

final IList<String> colors = ["red", "green", "blue", "orange", "pink"].lock;
print(colors.sublist(1, 3)); // [green, blue]

If end is omitted, it defaults to the length of this list.

print(colors.sublist(1));    // [green, blue, orange, pink]

The start and end positions must satisfy the relations 0 ≤ startendthis.length If end is equal to start, then the returned list is empty.

Implementation

IList<T> sublist(int start, [int? end]) {
  // TODO: Still need to implement efficiently.
  return IList._unsafeFromList(toList(growable: false).sublist(start, end), config: config);
}