Maps in Dart
Published in
Apr 7, 2024
Lesson#8
Maps are key-value pairs.
void main() {
var capitals = {
"Pakistan": "Islamabad",
"Afghanistan": "Kabul",
"Saudi Arabia": "Riyadh"
};
print(capitals); // {Pakistan: Islamabad, Afghanistan: Kabul, Saudi Arabia: Riyadh}
print(capitals["Pakistan"]); // Islamabad
print(capitals.keys); // (Pakistan, Afghanistan, Saudi Arabia)
print(capitals.values); // (Islamabad, Kabul, Riyadh)
capitals["India"]="New Delhi";
print(capitals); // {Pakistan: Islamabad, Afghanistan: Kabul, Saudi Arabia: Riyadh, India: New Delhi}
capitals.remove("India");
print(capitals); // {Pakistan: Islamabad, Afghanistan: Kabul, Saudi Arabia: Riyadh}
capitals.clear();
print(capitals); // {}
}