Set 集合去重 没有顺序且不能重复
s1.add("beijing");
s1.add("nanjing");
print(s1);// {beijing, nanjing}
print(s1.toList());//[beijing, nanjing]
List l1=["北京","上海","深圳","苏州","广州","上海"];
var s2=new Set();
s2.addAll(l1);
print(s2);
Map
属性
keys获取所有key values获取所有value isEmpty isNotEmpty
方法
remove(key) addAll({})合并映射 containsValue:查看映射内的值 返回 true/false
map where any every
1)
var person={
"name":"李白",
"age":20
};
var p2=new Map();
p2["name"]="杜甫";
p2["age"]=33;
print(p2);//{name: 杜甫, age: 33}
print(p2.keys);
Map p3={};
p3.addAll({
"sex":"male",
"location":"shanghai",
"hobby":["run","swim"]
});
print(p3);
p3.remove("sex");
print(p3);
print(p3.containsValue("shanghai")); //true
遍历3种
List l1=["北京","上海","苏州","广州","重庆"];
for(var i=0;i<l1.length;i++){
print(l1[i]);
};
for (var element in l1) {
print(element);
};
l1.forEach((value){
print("$value hello");
});
修改
var l2=[6,7,8];
var newl2=l2.map((value){ //修改集合数据
return value*2;
});
判断查找1:list
var l1=[6,5,4,7,8,9];
var newList=l1.where((value){
return value>6;
});
print(newList.toList());
var f=l1.any((value){//有一个满足
return value>5;
});
print(f);//true
var q=l1.every((value){
return value>5;//false
});
print(q);//false 全部满足
判断查找2:map
//set
var s=new Set();
s.addAll([89,98,54]);
s.forEach((value)=>print(value));//只有一行代码可以用箭头函数
//map
var p1={
"name":"libai",
"age":21
};
p1.forEach((key, value) {
print("$key---$value");
});