gpt4 book ai didi

flutter - Dart :将 map 转换为2个列表

转载 作者:行者123 更新时间:2023-12-03 03:12:09 25 4
gpt4 key购买 nike

我正在尝试将以下 map 转换为2个列表。

Map map = {'Jack': 'red', 'Adam': 'blue', 'Katherin': 'green'};

我想成为这样:(顺序很重要)
List myList1 = ['Jack', 'Adam', 'Katherin'];
List myList2 = ['red', 'blue', 'green'];

这可能吗,怎么办?
我搜索了槽栈溢出,并且响应给了我这个列表(不是我要搜索的内容)
[{ Jack, 'red' }, { Adam, 'blue' }, { Katherin, 'green' }] // not what I need

感谢您的帮助和努力!

最佳答案

如果我的问题正确,那么您正在寻找的内容已经内置在Map Class中。看一看:

Map map = {'Jack': 'red', 'Adam': 'blue', 'Katherin': 'green'};

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

输出:
[Jack, Adam, Katherin]
[red, blue, green]

我希望这是您要寻找的。

关于flutter - Dart :将 map 转换为2个列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59446986/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com