【问题标题】:What is difference between firstWhere() and indexWhere() in Dart ListDart List 中的 firstWhere() 和 indexWhere() 有什么区别
【发布时间】:2019-12-21 17:20:07
【问题描述】:

我在 Dart 中使用 List 时遇到了 firstWhere() 和 indexWhere() ,但这两个似乎有相同的工作。他们之间有什么区别吗。它们的用例是什么??

【问题讨论】:

  • firstWhere 返回List 的元素,indexWhere 返回整数索引

标签: list flutter dart


【解决方案1】:

firstWhereindexWhere 的文档都清楚地说明了这一点。

  • 首先在哪里

返回满足给定谓词测试的第一个元素。

  • 索引位置

返回列表中满足所提供测试的第一个索引。

区别在于firstWhere返回的是元素,而indexWhere返回的是匹配测试的索引。

【讨论】:

    猜你喜欢
    • 2014-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-04
    • 2020-08-16
    • 1970-01-01
    • 2014-01-21
    • 2019-08-19
    相关资源
    最近更新 更多