isEmpty, isNotEmpty, keys, values, length, addAll, addEntries
main() {
Map price = {
"iPhone" : 1500000,
"Galaxy" : 1000000,
"Apple Watch" : 500000,
};
print(price.isEmpty);
print(price.isNotEmpty);
print(price.keys);
print(price.values);
print(price.length);
print("\n--- map 추가하기 ---");
price.addAll({
'AirPods': 390000,
'Trackpad' : 100000
});
print(price);
price.addEntries([
MapEntry('xiaomi', 500000),
MapEntry('MacBook', 2500000)
]);
print(price);
price['test'] = 9999;
print(price);
}
update, ifAbsent, putIfAbsent, upadateAll
main() {
Map price = {
"iPhone" : 1500000,
"Galaxy" : 1000000,
"Apple Watch" : 500000,
};
price.update("iPhone", (value) => value = 2000000);
//price.update("iPhone", (value){
// return value = 2000000;
// });
print(price);
price.update("MacBook", (value) => value = 3000000,
ifAbsent: (){return 2222;});
// ↳먄약 위에 적은 "MacBook" 이 존재하지 않을 경우 key와 value를 새로 만
print(price);
price.putIfAbsent("MacBook Pro", () => 33333333);
print("\n-- putIfAbsent 사용 --");
print(price);
print("\n--- upadateAll 사용 ---");
price.updateAll((key, value) => value.toString() + '원');
// price.updateAll((key, value) {return value.toString() + '원';});
print(price);
}
삭제 관련 remove, removeWhere
main() {
Map price = {
"iPhone" : 1500000,
"Galaxy" : 1000000,
"Apple Watch" : 500000,
};
price.remove("Apple Watch");
print(price);
// 조건에 맞는 것을 삭제함
price.removeWhere((key, value) => key == "iPhone");
print(price);
}
'Dart' 카테고리의 다른 글
JSON 데이터 주고받기 (0) | 2021.06.23 |
---|---|
Dart - 비동기 통신 (Future, async, await, then) (0) | 2021.06.14 |
Dart 자료형 - List 심화 (0) | 2021.06.13 |
Dart 인터페이스 (0) | 2021.06.13 |
Dart static 사용 (0) | 2021.06.13 |