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 list
var myList = [3, 6, 'Avogados', 'Bag', 'Apple', 'four', 'five'];
// display list
print('The list before removing the list element ${myList}');
// remove items from index 2 to 4
// using removeRange()
myList.removeRange(2, 5);
// display list
print('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.
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources