What is the List.fillRange() method in Dart?

Overview

The fillRange() method overwrites a range of elements in the list with fillValue.

Syntax

```dart void fillRange( int start, int end, [E? fillValue] ) ```

Parameters

  • start: Represents the start index.
  • end: Represents the end index.
  • fillValue: Represents the value to be filled within the specified range in the list.

Return type

*void*

The illustration below shows the visual representation of the list.fillRange() method.

Visual representation of the fillRange() method

Code

The following code shows how to use the `fillRange()` method in Dart:
void main(){
// Creating list
var numbers = [14, 21, 58, 30, 76, 93, 28];
// Display result
print("Original list: $numbers");
// Overwriting items in the list
// using fillRange()
numbers.fillRange(1, 3, -10);
print('New list: ${numbers}');
}

Free Resources