Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

dart
communitycreator

What is the map.clear() method in Dart?

Harris Amjad

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 map.clear() function in Dart is used to remove all of the elements (key-value pairs) in the map.

The illustration below shows the visual representation of the map.clear() function.

Visual representation of the map.clear() function

Syntax

void map_name.clear()

map_name is the name of the map.

Parameters

The map.clear() function does not require any parameters.

Return value

Dart’s map.clear() function is used to erase all of the map’s elements (key-value pairs).

Code

The code below shows how to use the map.clear() function in Dart.

import 'dart:convert';

void main() {
  var map = new Map();

  map [1] = 'Tom';
  map [2] = 'Alsvin';
  map [3] = 'Eddie';
  //map containg key value pairs before clear
  print("map before clear: ${map}");

  //map after clear
  map.clear();
  print("map after clear: ${map}");

}

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