Dart-programming-removing-list-items
提供:Dev Guides
Dartプログラミング-リストアイテムの削除
dart:coreライブラリのListクラスでサポートされている次の関数を使用して、リスト内のアイテムを削除できます。
List.remove()
List.remove()関数は、リスト内の指定されたアイテムの最初の出現を削除します。 この関数は、指定された値がリストから削除された場合にtrueを返します。
構文
List.remove(Object value)
どこで、
- 値-リストから削除する必要があるアイテムの値を表します。
次の*例*は、この機能を使用する方法を示しています-
void main() {
List l = [1, 2, 3,4,5,6,7,8,9];
print('The value of list before removing the list element ${l}');
bool res = l.remove(1);
print('The value of list after removing the list element ${l}');
}
それは次の出力を生成します-
The value of list before removing the list element [1, 2, 3, 4, 5, 6, 7, 8, 9]
The value of list after removing the list element [2, 3, 4, 5, 6, 7, 8, 9]
List.removeAt()
*List.removeAt* 関数は、指定されたインデックスの値を削除して返します。
構文
List.removeAt(int index)
どこで、
- index -リストから削除する必要がある要素のインデックスを表します。
次の*例*は、この機能を使用する方法を示しています-
void main() {
List l = [1, 2, 3,4,5,6,7,8,9];
print('The value of list before removing the list element ${l}');
dynamic res = l.removeAt(1);
print('The value of the element ${res}');
print('The value of list after removing the list element ${l}');
}
それは次の出力を生成します-
The value of list before removing the list element [1, 2, 3, 4, 5, 6, 7, 8, 9]
The value of the element 2
The value of list after removing the list element [1, 3, 4, 5, 6, 7, 8, 9]
List.removeLast()
- List.removeLast()*関数は、リストの最後のアイテムをポップして返します。 同じための構文は以下のとおりです-
List.removeLast()
次の*例*は、この機能を使用する方法を示しています-
void main() {
List l = [1, 2, 3,4,5,6,7,8,9];
print('The value of list before removing the list element ${l}');
dynamic res = l.removeLast();
print('The value of item popped ${res}');
print('The value of list after removing the list element ${l}');
}
それは次の出力を生成します-
The value of list before removing the list element [1, 2, 3, 4, 5, 6, 7, 8, 9]
The value of item popped 9
The value of list after removing the list element [1, 2, 3, 4, 5, 6, 7, 8]
List.removeRange()
- List.removeRange()*関数は、指定された範囲内のアイテムを削除します。 同じための構文は以下のとおりです-
List.removeRange(int start, int end)
どこで、
- 開始-アイテムを削除するための開始位置を表します。
- 終了-アイテムの削除を停止するリスト内の位置を表します。
次の例は、この機能を使用する方法を示しています-
void main() {
List l = [1, 2, 3,4,5,6,7,8,9];
print('The value of list before removing the list element ${l}');
l.removeRange(0,3);
print('The value of list after removing the list
element between the range 0-3 ${l}');
}
それは次の出力を生成します-
The value of list before removing the list element
[1, 2, 3, 4, 5, 6, 7, 8, 9]
The value of list after removing the list element
between the range 0-3 [4, 5, 6, 7, 8, 9]