The set.isEmpty
function in Dart is used to check if a set is empty. The set.isEmpty
function returns true
if the set is empty. Otherwise, it returns false
.
The illustration below shows the visual representation of the set.isEmpty
function.
In Dart, a
set
is a particular instance in a list in which all of the inputs are unique.
dart:core
is required in order to use this function.
bool set_name.isEmpty
set_name
is the name of the set.
The set.isEmpty
function does not require any parameters.
If the set is empty, the set.isEmpty
function returns true
. Otherwise, it returns false
.
If there are duplicates, then the set will only keep the first instance, i.e.,
{'Tom','Alsvin','Eddie','Tom'}
will result in{'Tom','Alsvin','Eddie'}
.
The code below shows how to use the set.isEmpty
function in Dart.
import 'dart:convert';import 'dart:core';void main() {Set<String> set_1 = {'Tom','Alsvin','Eddie'};//set containing unique valueprint("set_1 is empty: ${set_1.isEmpty}");//empty setSet<String> set_2 = {};print("set_2 is empty: ${set_2.isEmpty}");//set containing non-unique valueSet<String> set_3 = {'Tom','Alsvin','Eddie','Tom'};print("set_3 is empty: ${set_3.isEmpty}");}