Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

dart
map
communitycreator

What is the map.isEmpty 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.isEmpty function in Dart is used to check if a map is empty or not.

map.isEmpty returns true if the map is empty, i.e., no key-value pairs exist. Otherwise, it returns false.

The illustration below shows a visual representation of the map.isEmpty function:

Visual representation map.isEmpty function

Syntax

bool map_name.isEmpty

map_name is the name of the map.

Parameter

The map.isEmpty function does not require any parameters.

Return value

If the map is empty, the map.isEmpty function returns true.

Otherwise, it returns false.

Code

The following code shows how to use map.isEmpty function in Dart:

import 'dart:convert';
void main() {
var map_1 = new Map();
map_1 [1] = 'Tom';
map_1 [2] = 'Alsvin';
map_1 [3] = 'Eddie';
//map containg key value pairs
print("map_1 is empty: ${map_1.isEmpty}");
//map empty
var map_2 = new Map();
print("map_2 is empty: ${map_2.isEmpty}");
}

RELATED TAGS

dart
map
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