oid main() {
Map<String, String> personalInfo = {
'姓名': '张三',
'学号': '20230001',
'年龄': '20',
'性别': '男'
};
personalInfo['成绩'] = '90';
personalInfo.putIfAbsent('排名', () => '第一');
personalInfo.remove('性别');
print('方法一:使用for-in循环遍历输出');
for (String key in personalInfo.keys) {
print('${key}: ${personalInfo[key]}');
}
print('\n方法二:使用Map的entries遍历输出');
personalInfo.entries.forEach((entry) {
print('${entry.key}: ${entry.value}');
});
print('\n方法三:使用Map的forEach遍历输出');
personalInfo.forEach((value, key) {
print('${key}: ${value}');
});
}