Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

dart
communitycreator

What is List replaceRange() 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.

The replaceRange() function

To update List elements, you can use the replaceRange() function from the dart:core library’s List class.

The replaceRange() method replaces the value of the element(s) within the provided range.

Syntax

List.replaceRange(int start_index, int end_index, Iterable <items>)

Parameters

  • start_index: An integer value that represents the index position at which the replacement should begin.

  • end_index: An integer value that represents the index position before which the replacement should terminate.

  • <items>: An iterable object with the modified values.

Return value

This method does not return a value.

Example

The following example demonstrates how to use the replaceRange() method in dart. Click on the “Run” button to execute the code.

void main() {
// Creating List
List<String> fruits = ["Orange","Apple", "Mango", "Banana", "Avocado"];
// display result
print('The list item before replacing: ${fruits}');
// replace items using replaceRange()
fruits.replaceRange(0,3,["Pineapple", "Pawpaw", "Lemon",]);
// display updated result
print('The new list after replacing the items between the range [0-3] is ${fruits}');
}

RELATED TAGS

dart
communitycreator

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.

Keep Exploring