gpt4 book ai didi

string - 如何在 Dart 语言中按字母顺序对字符串列表进行排序?

转载 作者:行者123 更新时间:2023-12-02 05:13:40 36 4
gpt4 key购买 nike

我有4家公司,每家公司都有10多个分公司。如果用户选择一家公司,我需要使用 showDialog 显示所选的公司分支机构。到这里一切都按预期进行。我的问题是我无法排序 List<String>按字母顺序排列。

知道如何在 Dart 中按字母顺序对字符串列表 (List) 进行排序吗?

List<String> _myBranchListName;

最佳答案

  • Flutter是一个应用程序开发SDK

  • Dart 是一种通用编程语言

  • Flutter 应用程序是用 Dart 编写的

  • 所以:

    How to sort A to Z in Flutter List< String > ?

  • 将会

    How to sort A to Z in Dart List< String > ?

  • A 到 Z :按字母顺序命名:

    How to sort alphabetically in Dart List< String > ?

  • List< String > :是字符串类型的列表所以

    How to sort alphabetically in Dart String List?

  • 更多

    How to sort a string list alphabetically in Dart language?

代码:

main() {
List<String> _myBranchListName= ['k branch', 'a branch', 'f branch'];

_myBranchListName.sort();
print(_myBranchListName);

//[a branch, f branch, k branch]
}

更新

I have a custom list with menas list contain class produt and product contain varable title and now i need to short my list based on title how to do it''' comment

sort method:

Sorts this list according to the order specified by the compare function.

The default List implementations use Comparable.compare if compare is omitted.

A Comparator may compare objects as equal (return zero),

even if they are distinct objects. The sort function is

not guaranteed to be stable, so distinct objects that

compare as equal may occur in any order in the result

  • 您的代码(😊Waring:我没有测试此代码,我需要您的反馈):

produts.sort((a, b) => a.title.compareTo(b.title));

关于string - 如何在 Dart 语言中按字母顺序对字符串列表进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54072525/

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