0
点赞
收藏
分享

微信扫一扫

#yyds干货盘点#Dart - 如何对 Map 的键进行排序

两岁时就很帅 2022-02-22 阅读 76


Flutter

import "dart:collection";

main() {
final SplayTreeMap<String, Map<String,String>> st =
SplayTreeMap<String, Map<String,String>>();

st["yyy"] = {"should be" : "3rd"};
st["zzz"] = {"should be" : "last"};
st["aaa"] = {"should be" : "first"};
st["bbb"] = {"should be" : "2nd"};

for (final String key in st.keys) {
print("$key : ${st[key]}");
}
}

// Output:
// aaa : first
// bbb : 2nd
// yyy : 3rd
// zzz : last

如果您想要对​​List​​对map的键进行排序:

var sortedKeys = map.keys.toList()..sort();

​​https://stackoverflow.com/questions/18244545/dart-how-to-sort-maps-keys​​

举报

相关推荐

0 条评论