What is the LinkedHashMap.isEmpty in Dart?
Overview
LinkedHashMap is a hash-table based on mapLinkedHashMap maintains the insertion order of the entries. Read more about LinkedHashMap here.
We can use the isEmpty property to check whether the map is empty (there is no key-value pair present in the LinkedHashMap).
Syntax
map.isEmpty
Return value
This property returns true if the LinkedHashMap is empty. Otherwise, false is returned.
Code
The below code demonstrates how to check if the LinkedHashMap is empty:
import 'dart:collection';void main() {//create a new LinkedHashMap which can have string type as key, and int type as valueLinkedHashMap map = new LinkedHashMap<String, int>();print('The map is $map');// use isEmpty property to check if the map is emptyprint('map.isEmpty : ${map.isEmpty}');// add two entries to the mapmap["one"] = 1;map["two"] = 2;print('\nThe map is $map');// use isEmpty property to check if the map is emptyprint('map.isEmpty : ${map.isEmpty}');}
Explanation
In the above code,
-
Line 4: We create a new
LinkedHashMapobject withmap. -
Line 8: We use the
isEmptyproperty to check if themapis empty. In our case, themapis empty, sotrueis returned. -
Lines 11 and 12: We add two new entries to the
map. Now the map is{one: 1, two: 2}. -
Line 16: We use the
isEmptyproperty to check if themapis empty. In our case, themapcontains two entries and is not empty, sofalseis returned.