Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

dart
communitycreator

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

Overview

The removeAt() method removes the value at the specified index in the list.

Syntax

The syntax of the function is as follows:

List_name.removeAt(int index);
The removeAt() syntax

Note: List_name is the name of the list.

Parameters

  • Index (required): The index of the element that should be removed from the list.

Return value

The removeAt() method returns the element that is removed from the list.

Code

The following code demonstrates the use of list.removeAt() in Dart.

void main() {
//Creating list
var myList = [2,6, 'Apple', 'Pen', 'three', 'Mango', 'five'];
// display result
print('The list before removing item from the list: ${myList}');
// Remove item using removeAt()
var res = myList.removeAt(3);
// Print result
print('The Item removed: ${res}');
print('The new list after removing the list element ${myList}');
}
Try it out!

Explanation

  • Line 3: We create a list called myList with seven elements.

  • Line 8: We use the removeAt() method to remove an item from the index position 3.

  • Lines 10 and 12: We display the result.

We can see that pen, the element at index position 3, is removed.

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