LinkedHashMap
is a hash-table
based on map
LinkedHashMap
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
).
map.isEmpty
This property returns true
if the LinkedHashMap
is empty. Otherwise, false
is returned.
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}');}
In the above code,
Line 4: We create a new LinkedHashMap
object with map.
Line 8: We use the isEmpty
property to check if the map
is empty. In our case, the map
is empty, so true
is 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 isEmpty
property to check if the map
is empty. In our case, the map
contains two entries and is not empty, so false
is returned.