What is List removeRange() in Dart?
The removeRange() method removes the items within the specified range in the list.
Syntax
List_name.removeRange(int start, int end);
Parameters
-
Start: This specifies the starting position for removing the items in the list. -
End: This specifies the position in the list to stop removing the items in the list.
Return type
The return type of the removeRange() method is void.
Code
The following code shows how to use the removeRange() method in Dart:
void main() {// Creating listvar myList = [3, 6, 'Avogados', 'Bag', 'Apple', 'four', 'five'];// display listprint('The list before removing the list element ${myList}');// remove items from index 2 to 4// using removeRange()myList.removeRange(2, 5);// display listprint('The new list after removing the list elements: ${myList}');}
Explanation
- Line 3: We create a
List. - Line 5: We display a
List. - Line 9: We remove elements from index 2 to index 4.
- Line 11: We display the
List.