slice method

List<T?> slice(
  1. int start, [
  2. int? end
])

Creates a slice of list from start up to endexclusive.

var list = [1, 2, 3, 4];

//It slices the list elements and hence modifies this list
list.slice(2); // list = [3, 4]

// Do not want to alter the list object ??
var list = [1, 2, 3, 4];

//It creates copy of list slices the list elements and creates new list
list.slice(2); // list = [3, 4]

Implementation

List<T?> slice(int start, [int? end]) {
  return _privateSlice(start, end);
}