Skip to main content

Flutter Dart LinkedHashMap Example

LinkedHashMap is the combination of Map and HashMap class. LinkedHashMap is used to preserve data insertion order. The values we enter in the LinkedHashMap is based on Key. 

Flutter Dart LinkedHashMap Example

1. Creating LinkedHashMap and assigning value.
final menByWeight = {93.33 : 'A'};
2. Adding next item to LinkedHashMap.
menByWeight[100] = 'B';
3. Adding multiple items together in LinkedHashMap.
 menByWeight.addAll({80.88: 'C', 40.22: 'D'});
4. Printing LinkedHashMap elements one by one on screen with forEach loop.
 menByWeight.forEach((key, value) {
  print('$key \t $value');
});
5. Checking LinkedHashMap is empty or not.
 print(menByWeight.isEmpty);
6. Get length(Items count) of LinkedHashMap.
print(menByWeight.length);
7. Checking LinkedHashMap for specific key is present or not.
final key1 = menByWeight.containsKey(80.88);
 print(key1);
8. Checking LinkedHashMap for specific Value is present or not.
 final value1 = menByWeight.containsValue('D');
 print(value1);
9. Remove a specific Key from LinkedHashMap.
  final removedValue = menByWeight.remove(80.88);
 print(removedValue);
10. Removing all values at once in LinkedHashMap.
menByWeight.clear();
Source code for main.dart file:
void main() { 
 final menByWeight = {93.33 : 'A'};
 print(menByWeight);
 menByWeight[100] = 'B';
 print(menByWeight);
 menByWeight.addAll({80.88: 'C', 40.22: 'D'});
 print(menByWeight);
 menByWeight.forEach((key, value) {
  print('$key \t $value');
});
 print(menByWeight.isEmpty);
 print(menByWeight.length);
 final key1 = menByWeight.containsKey(80.88);
 print(key1);
 final value1 = menByWeight.containsValue('D');
 print(value1);
 final removedValue = menByWeight.remove(80.88);
 print(removedValue);
 menByWeight.clear();
 print(menByWeight);
}
Output:
Flutter Dart LinkedHashMap Example

Comments