如何转换List <Doctor>项目= new List();列出<String>?你能帮助我吗?

时间:2019-06-14 05:59:08

标签: flutter dart

如何转换列表项= new List();列出?你能帮我吗?

2 个答案:

答案 0 :(得分:0)

List<Doctor> items = new List();

---将数据添加到items列表中---

然后

List<String> strings = new ArrayList<>(items.size());
for (Doctor doctor: items) {
    strings.add(Objects.toString(doctor, null));
}

如果您使用的是Java 8,

List<String> strings = items.stream()
   .map(doctor -> Objects.toString(doctor , null))
   .collect(Collectors.toList());

答案 1 :(得分:0)

https://api.dartlang.org/stable/2.4.0/dart-core/List-class.html

^使用.map实例的List<Doctor>方法。

例如

var itemStrings = items.map((doc) {
    // Title property as example
    return doc.title;
}).toList();

我建议您服用dart language tour