What is the map.isNotEmpty method in Dart?

The map.isNotEmpty function in Dart is used to check if a map is empty or not.

map.isNotEmpty returns true if the map is not empty and contains key value pairs; otherwise, it returns false.

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

Visual representation of the map.isNotEmpty function

Syntax

void map_name.isNotEmpty

map_name is the name of the queue.

Parameters

The map.isNotEmpty function does not require any parameters.

Return value

If the map is not empty, the map.isNotEmpty function returns true. Otherwise, it returns false.

Code

The following code shows how to use the map.isNotEmpty 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 not empty: ${map_1.isNotEmpty}");
//map empty
var map_2 = new Map();
print("map_2 is not empty: ${map_2.isNotEmpty}");
}
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources