- Dart Programming - HTML DOM
- Dart Programming - Unit Testing
- Dart Programming - Concurrency
- Dart Programming - Async
- Dart Programming - Libraries
- Dart Programming - Typedef
- Dart Programming - Debugging
- Dart Programming - Exceptions
- Dart Programming - Packages
- Dart Programming - Generics
- Dart Programming - Collection
- Dart Programming - Object
- Dart Programming - Classes
- Dart Programming - Interfaces
- Dart Programming - Functions
- Dart Programming - Enumeration
- Dart Programming - Runes
- Dart Programming - Symbol
- Dart Programming - Map
- Dart Programming - Lists
- Dart Programming - Lists
- Dart Programming - Boolean
- Dart Programming - String
- Dart Programming - Numbers
- Dart Programming - Decision Making
- Dart Programming - Loops
- Dart Programming - Operators
- Dart Programming - Variables
- Dart Programming - Data Types
- Dart Programming - Syntax
- Dart Programming - Environment
- Dart Programming - Overview
- Dart Programming - Home
Dart Programming Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Dart Programming - Map
The Map object is a simple key/value pair. Keys and values in a map may be of any type. A Map is a dynamic collection. In other words, Maps can grow and shrink at runtime.
Maps can be declared in two ways −
Using Map Literals
Using a Map constructor
Declaring a Map using Map Literals
To declare a map using map pterals, you need to enclose the key-value pairs within a pair of curly brackets "{ }".
Here is its syntax −
var identifier = { key1:value1, key2:value2 [,…..,key_n:value_n] }
Declaring a Map using a Map Constructor
To declare a Map using a Map constructor, we have two steps. First, declare the map and second, initiapze the map.
The syntax to declare a map is as follows −
var identifier = new Map()
Now, use the following syntax to initiapze the map −
map_name[key] = value
Example: Map Literal
void main() { var details = { Usrname : tom , Password : pass@123 }; print(details); }
It will produce the following output −
{Usrname: tom, Password: pass@123}
Example: Adding Values to Map Literals at Runtime
void main() { var details = { Usrname : tom , Password : pass@123 }; details[ Uid ] = U1oo1 ; print(details); }
It will produce the following output −
{Usrname: tom, Password: pass@123, Uid: U1oo1}
Example: Map Constructor
void main() { var details = new Map(); details[ Usrname ] = admin ; details[ Password ] = admin@123 ; print(details); }
It will produce the following output −
{Usrname: admin, Password: admin@123}
Note − A map value can be any object including NULL.
Map – Properties
The Map class in the dart:core package defines the following properties −
Sr.No | Property & Description |
---|---|
1 | Returns an iterable object representing keys |
2 | Returns an iterable object representing values |
3 | Returns the size of the Map |
4 | Returns true if the Map is an empty Map |
5 | Returns true if the Map is an empty Map |
Map - Functions
Following are the commonly used functions for manipulating Maps in Dart.
Sr.No | Function Name & Description |
---|---|
1 |
Adds all key-value pairs of other to this map. |
2 |
Removes all pairs from the map. |
3 |
Removes key and its associated value, if present, from the map. |
4 |
Apppes f to each key-value pair of the map. |