dart:core
庫中Set.add
方法的用法介紹如下。
用法:
bool add(
E value
)
將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 Set.addAll用法及代碼示例
- Dart Set.removeWhere用法及代碼示例
- Dart Set.from用法及代碼示例
- Dart Set.remove用法及代碼示例
- Dart Set.retainAll用法及代碼示例
- Dart Set.contains用法及代碼示例
- Dart Set.retainWhere用法及代碼示例
- Dart Set.union用法及代碼示例
- Dart Set.unmodifiable用法及代碼示例
- Dart Set.difference用法及代碼示例
- Dart Set.clear用法及代碼示例
- Dart Set.containsAll用法及代碼示例
- Dart Set.removeAll用法及代碼示例
- Dart Set.lookup用法及代碼示例
- Dart Set.of用法及代碼示例
- Dart Set.intersection用法及代碼示例
- Dart SetMixin.forEach用法及代碼示例
- Dart SetMixin.addAll用法及代碼示例
- Dart SetMixin.reduce用法及代碼示例
- Dart SetMixin.removeAll用法及代碼示例
- Dart SetMixin.add用法及代碼示例
- Dart SetMixin.expand用法及代碼示例
- Dart SetMixin.elementAt用法及代碼示例
- Dart SetMixin.contains用法及代碼示例
- Dart SetMixin.containsAll用法及代碼示例
注:本文由純淨天空篩選整理自dart.dev大神的英文原創作品 add method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。