Identifier = new Set()
or
Identifier = new Set.from(Iterable)
# HashMap
Identifier= new HashMap()
Example
import 'dart:collection';
main() {
var accounts = new HashMap();
accounts['dept']='BA';
accounts['name']='Kim';
accounts['email']='[email protected]';
print('Map after adding entries :${accounts}');
}
=> output
Map after adding entries :{email: [email protected], dept: BA, name: Kim}
Adding Multiple Values to a HashMap
HashMap.addAll(Iterable)
Example
import 'dart:collection';
main() {
var accounts = new HashMap();
accounts.addAll({'dept':'BA','email':'[email protected]'});
print('Map after adding entries :${accounts}');
}
=> output
Map after adding entries :{email: [email protected], dept: BA}
Removing Values from a HashMap
import 'dart:collection';
main() {
var accounts = new HashMap();
accounts['dept'] = 'BA';
accounts['name'] = 'Kim';
accounts['email'] = '[email protected]';
print('Map after adding entries :${accounts}');
accounts.remove('dept');
print('Map after removing entry :${accounts}');
accounts.clear();
print('Map after clearing entries :${accounts}');
}
=> output
Map after adding entries :{email: [email protected], dept: BA, name: Kim}
Map after removing entry :{email: [email protected], name: Kim}
Map after clearing entries :{}
# HashSet
Identifier = new HashSet()
Adding Multiple Values to a HashSet
addAll()
function allows adding multiple values to the HashSet.
import 'dart:collection';
void main() {
Set numberSet = new HashSet();
numberSet.addAll([10,20,30]);
print("Default implementation :${numberSet.runtimeType}");
for(var no in numberSet){
print(no);
}
}
=> output
Default implementation :_HashSet
200
300
100
Removing Values from a HashSet
remove()
function removes the value passed to it.
clear()
function removes all the entries from the HashSet.
import 'dart:collection';
void main() {
Set numberSet = new HashSet();
numberSet.addAll([10,20,30]);
print("Printing hashet.. ${numberSet}");
numberSet.remove(10);
print("Printing hashet.. ${numberSet}");
numberSet.clear();
print("Printing hashet.. ${numberSet}");
}
=> output
Printing hashet.. {20, 30, 10}
Printing hashet.. {20, 30}
Printing hashet.. {}