dart:core 庫中List.setRange 方法的用法介紹如下。
用法:
void setRange(
int start,
int end,
Iterable<E> iterable,
[int skipCount = 0]
)
將iterable 的一些元素寫入此列表的範圍。
將 iterable 的對象,首先跳過 skipCount 對象,複製到此列表的從 start (含)到 end (不含)的範圍內。
final list1 = <int>[1, 2, 3, 4];
final list2 = <int>[5, 6, 7, 8, 9];
// Copies the 4th and 5th items in list2 as the 2nd and 3rd items
// of list1.
const skipCount = 3;
list1.setRange(1, 3, list2, skipCount);
print(list1); // [1, 8, 9, 4]
start 和 end 提供的範圍必須有效。如果 0 ≤ start ≤ end ≤ length ,則從 start 到 end 的範圍是有效的。空範圍(帶有 end == start )是有效的。
跳過 skipCount 對象後,iterable 必須有足夠的對象來填充從 start 到 end 的範圍。
如果 iterable 是此列表,則即使兩個範圍重疊,該操作也會正確地將最初在 skipCount 到 skipCount + (end - start) 範圍內的元素複製到範圍 start 到 end 。
如果iterable 以其他方式依賴於該列表,則不作任何保證。
相關用法
- Dart List.setAll用法及代碼示例
- Dart List.sort用法及代碼示例
- Dart List.shuffle用法及代碼示例
- Dart List.sublist用法及代碼示例
- Dart List.first用法及代碼示例
- Dart List.fillRange用法及代碼示例
- Dart List.addAll用法及代碼示例
- Dart List.indexOf用法及代碼示例
- Dart List.removeWhere用法及代碼示例
- Dart List.reversed用法及代碼示例
- Dart List.removeRange用法及代碼示例
- Dart List.unmodifiable用法及代碼示例
- Dart List.clear用法及代碼示例
- Dart List.length用法及代碼示例
- Dart List.from用法及代碼示例
- Dart List.removeAt用法及代碼示例
- Dart List.lastIndexWhere用法及代碼示例
- Dart List.retainWhere用法及代碼示例
- Dart List.removeLast用法及代碼示例
- Dart List.filled用法及代碼示例
- Dart List.empty用法及代碼示例
- Dart List.of用法及代碼示例
- Dart List.replaceRange用法及代碼示例
- Dart List.remove用法及代碼示例
- Dart List.asMap用法及代碼示例
注:本文由純淨天空篩選整理自dart.dev大神的英文原創作品 setRange method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
