sublist method Null safety

  1. @override
GpsPointsCollection<T> sublist(
  1. int start,
  2. [int? end]

Returns a new collection of the same type as the current collection containing the elements between start and end.

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

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


GpsPointsCollection<T> sublist(int start, [int? end]) {
  end = RangeError.checkValidRange(start, end, length, 'start', 'end',
      'incorrect parameters for sublist() call');

  final result = newEmpty() as GpsPointsCollection<T>;

  result.addAllStartingAt(this, start, end - start);
  return result;