Spec-Zone.ru › Dart 1

dart:collection

Метод sublist

List<E> sublist(int start, [ int end ])

Возвращает новый список, содержащий объекты от start включительно до end, не включая.

List<String> colors = ['red', 'green', 'blue', 'orange', 'pink'];
colors.sublist(1, 3); // ['green', 'blue']

Если end опущено, используется length от this.

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

Возникает ошибка, если start находится вне диапазона 0 .. length или если end находится вне диапазона 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 = new List<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/1.24.3/dart-collection/ListMixin/sublist.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API