Maps Hashmaps
void main() {
///When we use by literal in map_name, when initially you have to give any value
///then you can give value by open curly bracket
// var map_name = {
// "Name" : "Value1",
// "YearOfExperience" : 2,
// "Avg.Rating" : 3.0,
// "CanLocateToOffice" : true,
// "Key5" : false,
// "MCQ_Answer" : "a"
// };
//print(map_name);
//print(map_name["Key3"],); //Output : 3.0
//print(map_name["Key"],); //Output : null
//map_name["Key7"] = "Raman"; //Adding new key in the given Map map_name
// map_name["Key5"] = "Ramanujan"; //Updating Value of Key
// print(map_name);
/// Only method is different but implementation is same
///If you want to add value at run time then you can create object of map & you can add data in key-value pair in
///whatever object you have taken
var mapName = Map();
mapName["Name"] = "Vishal";
mapName["YearOfExperience"] = 7;
mapName["Avg.Rating"] = 55.29;
mapName["CanLocateToOffice"] = true;
mapName["Key5"] = false;
mapName["MCQ_Answer"] = "b";
if(!mapName.isNotEmpty) // isnotempty
{
print("is empty");
}
// print(mapName);
// print(mapName.isEmpty); //Checking whether given Map is Empty OR Not
// print(mapName.isNotEmpty); //Checking whether given Map is NotEmpty
// print(mapName.length); //Measuring the length of the given Map
// print(mapName.keys); //Getting all keys present in the given Map
// print(mapName.values); //Getting all values present in the given Map
// print(mapName.containsKey("CanLocateToOffice"),); //Checking whether given Key is present OR Not in Map
// print(mapName.containsValue(false),); //Checking whether given key exist OR Not in mapName Map
// print(mapName.remove("CanLocateToOffice"),); //Removing the given key data from Map
// print(mapName); //Printing the whole Map (with "Key" : Value,)
//when you will dynamic your app in Flutter, Whenever you make the application dynamic, the role of the Json increases,
//Whenever the API is formed. What is API ? => When your phone communicates with the server with the help of API, in the
//API we have to send some value along OR if some data is coming from there, then in that case the role of the map is very
//useful because the keys-value pair is also there.This map data type is of the same type. Whenever we make the app dynamic
//in the building process of the app, then the role of the map will increase in that case.There we will understand the real
//use of why maps are used.
/// Another method for declaration of Map
var map1 = Map<int, String>();
map1[2] = "cap";
map1[3] = "toy";
map1[4] = "bus";
map1[5] = "room";
//print(map1);
/// Another method for declaring Map
Map<String, String> mapOther = {
"A" : "rahul",
"B" : "bob",
"C" : "rony" };
// print(mapOther.length);
// print(mapOther);
}
Comments
Post a Comment