在列表Scala中查找元素的索引 [英] Finding the index of an element in a list scala

查看:487
本文介绍了在列表Scala中查找元素的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Scala列表中找到元素的索引.

How do I find the index of an element in a Scala list.

val ls = List("Mary", "had", "a", "little", "lamb")

如果我要求小"的索引,我需要得到3

I need to get 3 if I ask for the index of "little"

推荐答案

scala> List("Mary", "had", "a", "little", "lamb").indexOf("little")
res0: Int = 3

您可以尝试阅读 scaladoc以获得列表下次. ;)

You might try reading the scaladoc for List next time. ;)

这篇关于在列表Scala中查找元素的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆