声明
不指定泛型
1 | var map1 = {'aa':'aaa','bb':22,'cc':true};//直接赋初始值 |
指定泛型
1 | var map333 = <String,String>{}; |
属性
1 | Map<String,int> map6 = {"a":1,"b":2}; |
方法
新增一个key-value
1 | Map<String,int> map7 = {"a":1,"b":2,"c":3,"d":4,"e":5}; |
修改一个key的value
1 | Map<String,int> map8 = {"a":1,"b":2,"c":3,"d":4,"e":5}; |
update() 对指定的key的value做出修改
1 | Map<String,int> map23 = {"a":1,"b":2,"c":3}; |
updateAll() 根据参数函数的规则,批量修改map
1 | Map<String,int> map24 = {"a":1,"b":2,"c":3}; |
remove() 删除一个key
1 | Map<String,int> map9 = {"a":1,"b":2,"c":3,"d":4,"e":5}; |
removeWhere() 根据条件批量删除
1 | Map<String,int> map10 = {"a":1,"b":2,"c":3,"d":4,"e":5}; |
containsKey() 是否包含key
1 | Map<String,int> map11 = {"a":1,"b":2,"c":3,"d":4,"e":5}; |
containsValue() 是否包含value值
1 | Map<String,int> map17 = {"a":1,"b":2,"c":3}; |
forEach() 遍历
1 | Map<String,int> map12 = {"a":1,"b":2,"c":3,"d":4,"e":5}; |
map() 遍历每个元素
根据参数函数,对keyvalue做出修改,可转换成其他泛型的Map
1 | Map<String,int> map19 = {"a":1,"b":2,"c":3}; |
clear() 清空map
1 | Map<String,int> map15 = {"a":1,"b":2,"c":3}; |
addAll() 整体合并另一个map 泛型要一致
1 | Map<String,int> map16 = {"a":1,"b":2,"c":3}; |
addEntries() 合并两个map 如果key有重复,被合并的map的value覆盖前者
1 | Map<String,int> map26 = {"a":1,"b":2,"c":3}; |
putIfAbsent() 存在key就获取值,不存在则添加到map 然后返回值
1 | Map<String,int> map18 = {"a":1,"b":2,"c":3}; |
cast() 泛型类型提升为其父祖类
1 | Map<String,int> map21 = {"a":1,"b":2,"c":3}; |