In dart LinkedHashSet works as a hash table including on a set implementation. LinkedHashSet is used where we want to keep track of the inserted data order.
Flutter Dart LinkedHashSet Example
1. Creating Empty LinkedHashSet.
final tempName = <String>{};
2. Creating LinkedHashSet with default filled values.
final tempName = <String>{'A', 'B'};
print(tempName);
3. Adding multiple values together in LinkedHashSet.
tempName.addAll({'C', 'D', 'E', 'F'});
4. Checking LinkedHashSet is Empty or Not.
print(tempName.isEmpty);
5. Get the length of LinkedHashSet.
print(tempName.length);
6. Find and check if certain value is present or not in LinkedHashSet.
final b_Exists = tempName.contains('B');
print(b_Exists);
7. Print all LinkedHashSet on Terminal screen one by one with For Each loop.
tempName.forEach(print);
8. Removing Single item from LinkedHashSet.
tempName.remove('E');
9. Creating a duplicate copy of LinkedHashSet.
final copy = tempName.toSet();
print(copy);
Source code for main.dart file:
void main() {
final tempName = <String>{'A', 'B'};
print(tempName);
tempName.addAll({'C', 'D', 'E', 'F'});
print(tempName);
print(tempName.isEmpty);
print(tempName.length);
final b_Exists = tempName.contains('B');
print(b_Exists);
tempName.forEach(print);
tempName.remove('E');
print(tempName);
final copy = tempName.toSet();
print(copy);
}
Output:
Comments
Post a Comment