Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

communitycreator
dart

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

Maria Elijah

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

Overview

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

Syntax

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}');
}

RELATED TAGS

communitycreator
dart

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring