Set

 /// Set : A set in Dart is an unordered collection of unique items

/// Features of Set : Different outputs, Unique elements, Unordered Index

import "dart:collection";

void main() {
/// Set declaration
// Set set1 = {"bus", "car", "truck"};
// print(set1);
// var set2 = {1, 2, 3, 4, 5, 6};
// print(set2);

/// 2nd Way to declare Set
// Set set3 = new Set(); //Set declaration
// set3.add(10);
// set3.add(20);
// print(set3);

/// Declaring Empty Set
// Set set4 = {};
// print(set4);

/// Declaring the Set type
// Set set5 = {}; // Set declaration
// var set6 = {}; // Map declaration
// print(set5.runtimeType);
// print(set6.runtimeType);

/// printing Set elements using for in loop
// Set set7 = {10, 20};
// for(int i in set7) {
// print(i);
// }

/// Constant Set declaration using "const" keyword
// Set set8 = const {10, 20, 30};
// //set8.add(40); //Unsupported Operation
// for(int i in set8) {
// print(i);
// }

/// Set Methods
// Set set9 = {10, 20, 5, 100, 90, 55};
// print(set9);

/// Adding new elements in Set
// set9.add(85); //Adding Single Value
// print(set9);

//set9.addAll([2, 33]); //Adding Multiple Values in First Way
// set9.addAll({2, 33}); //Adding Multiple Values in Second Way
// print(set9);

/// Removing element from Set
// set9.remove(100);
// print(set9);

/// Length of Set
// print(set9.length);

/// Type of Set using runtimeType
// print(set9.runtimeType);

/// presence & absence of Set elements
// print(set9.isEmpty);
// print(set9.isNotEmpty);

/// Clearing the Set elements
// set9.clear();
// print(set9);

/// Declaring HashSet

Set hash1 = HashSet(); //Declaring HashSet

// hash1.add(10); //Adding Single value in HashSet
// print(hash1);

hash1.addAll([10, 20, 30, 40]); //Adding Multiple Values in HashSet
print(hash1);
}

Comments

Popular posts from this blog

Second GET API Calling with Bloc simple Example in Flutter

Stack Container Scrollable Card widget UI with Custom Widget

Pagination with Bloc Pattern in Flutter