码迷,mamicode.com
首页 > 编程语言 > 详细

Dart语言学习(七)Dart Map类型

时间:2020-01-27 18:49:54      阅读:291      评论:0      收藏:0      [点我收藏+]

标签:each   val   list   python   lse   span   port   support   不可   

Map创建

创建Map: var map1 = {"first":"Dart",1:true,true:"2"};
创建不可变Map: var map2 = const{"first":"Dart",1:true,true:"2"};

构造创建:var map3 = new Map();

常用操作

[],length,keys,values,
containsKey,
containsValue,
remove,forEach 

  var map1 = {"first":"Dart",1:true,true:"2"};
  print(map1);

  print(map1["first"]);
  print(map1[true]);
  map1[1] = false;
  print(map1);

  var map2 = const {1:"Dart",2:"Java"};
//  map2[1] = "Python"; //Unsupported operation: Cannot set value in unmodifiable Map

  var map3 = new Map();
  print(map3);

  var map = {"first":"Dart","second":"Java","third":"Python"};
  print(map.length);
//  map.isEmpty;

  print(map.keys);
  print(map.values);

  print(map.containsKey("first"));
  print(map.containsValue("C"));

  map.remove("third");
  print(map);

  map.forEach(f);

  var list = ["1","2","3"];
  print(list.asMap());

输出:

{first: Dart, 1: true, true: 2}
Dart
2
{first: Dart, 1: false, true: 2}
{}
3
(first, second, third)
(Dart, Java, Python)
true
false
{first: Dart, second: Java}
key=first,value=Dart
key=second,value=Java
{0: 1, 1: 2, 2: 3}

 





Dart语言学习(七)Dart Map类型

标签:each   val   list   python   lse   span   port   support   不可   

原文地址:https://www.cnblogs.com/jukaiit/p/12236576.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!