forked from smartherd/DartTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
34_set_and_hashset.dart
38 lines (27 loc) · 1.1 KB
/
34_set_and_hashset.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Objectives
// 1. Sets:
// --> Unordered Collection
// --> All elements are unique
void main() {
Set<String> countries = Set.from(["USA", "INDIA", "CHINA"]); // Method 1: From a list
countries.add("Nepal");
countries.add("Japan");
Set<int> numbersSet = Set(); // Method 2: Using Constructor
numbersSet.add(73); // Insert Operation
numbersSet.add(64);
numbersSet.add(21);
numbersSet.add(12);
numbersSet.add(73); // Duplicate entries are ignored
numbersSet.add(73); // Ignored
numbersSet.contains(73); // returns true if the element is found in set
numbersSet.remove(64); // returns true if the element was found and deleted
numbersSet.isEmpty; // returns true if the Set is empty
numbersSet.length; // returns number of elements in Set
// numbersSet.clear(); // Deletes all elements
print("\n");
for (int element in numbersSet) { // Using Individual Element ( Objects )
print(element);
}
print("\n");
numbersSet.forEach((element) => print(element)); // Using Lambda
}