Spec-Zone.ru › Dart 2

dart:collection

Метод difference

Set<E> difference(
  1. Set<Object?> other
)
override

Создаёт новый набор, содержащий элементы этого набора, которые отсутствуют в other.

То есть, возвращаемый набор содержит все элементы этого набора Set, которые не являются элементами other в соответствии с other.contains.

final characters1 = <String>{'A', 'B', 'C'};
final characters2 = <String>{'A', 'E', 'F'};
final differenceSet1 = characters1.difference(characters2);
print(differenceSet1); // {B, C}
final differenceSet2 = characters2.difference(characters1);
print(differenceSet2); // {E, F}

Реализация

Set<E> difference(Set<Object?> other) {
  Set<E> result = toSet();
  for (E element in this) {
    if (other.contains(element)) result.remove(element);
  }
  return result;
}

© 2012 the Dart project authors
Licensed under the BSD 3-Clause "New" or "Revised" License.
https://api.dart.dev/stable/2.18.5/dart-collection/SetMixin/difference.html

Spec-Zone.ru

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