當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Dart SplayTreeSet.add用法及代碼示例


dart:collection 庫中SplayTreeSet.add 方法的用法介紹如下。

用法:

bool add(
   E element   
)
      override

value 添加到集合中。

如果集合中還沒有value(或相等的值),則返回true。否則返回 false 並且集合不會改變。

例子:

final dateTimes = <DateTime>{};
final time1 = DateTime.fromMillisecondsSinceEpoch(0);
final time2 = DateTime.fromMillisecondsSinceEpoch(0);
// time1 and time2 are equal, but not identical.
assert(time1 == time2);
assert(!identical(time1, time2));
final time1Added = dateTimes.add(time1);
print(time1Added); // true
// A value equal to time2 exists already in the set, and the call to
// add doesn't change the set.
final time2Added = dateTimes.add(time2);
print(time2Added); // false

print(dateTimes); // {1970-01-01 02:00:00.000}
assert(dateTimes.length == 1);
assert(identical(time1, dateTimes.first));
print(dateTimes.length);

相關用法


注:本文由純淨天空篩選整理自dart.dev大神的英文原創作品 add method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。