What is the Set.isNotEmpty method in Dart?
The set.isNotEmpty function in Dart is used to check if a set is empty or not. set.isNotEmpty returns true if a set is not empty; otherwise, it returns false.
The image below shows the visual representation of the set.isNotEmpty function.
In Dart, a
setis a particular instance of a list in which all of the inputs are unique.
dart:coreis required in order to use this function.
Syntax
set_name.isNotEmpty
set_nameis the name of the set.
Parameter
The set.isNotEmpty function does not require any parameters.
Return value
If the set is not empty, the set.isNotEmpty function returns true; otherwise, it returns false.
If there are duplicates, then the set will only keep the first instance. For instance,
{'Tom','Alsvin','Eddie','Tom'}will result in{'Tom','Alsvin','Eddie'}.
Code
The code below shows how to use the set.isNotEmpty 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 not empty: ${set_1.isNotEmpty}");//empty setSet<String> set_2 = {};print("set_2 is not empty: ${set_2.isNotEmpty}");//set containing non-unique valueSet<String> set_3 = {'Tom','Alsvin','Eddie','Tom'};print("set_3 is not empty: ${set_3.isNotEmpty}");}