如何将选项[List [String]]转换为Scala中的列表[String]?
我的option
list
of string> string
ake of like, 一些(列表(“ ABC”,“ DEF”,“ GHI”))
,我需要转换为list(“ ABC”,“ DEF”,“ GHI”)在Scala中。我的意思是
option [list [String]]
to list [String]
。
I am having Option
of List
of String
like,Some(List("abc","def","ghi"))
and I need to convert to List("abc","def","ghi")
in Scala. I Mean Option[List[String]]
to List[String]
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该检查选项的文档。您会在那里找到所需的一切。
这是2个想法:
输出:
You should check the documentation for Option. You will find everything you'll need there.
Here are 2 ideas:
Output:
如果要删除Scala中的选项,则可以使用getorelse()函数。
Scala是一种非常强大的类型语言,可检测编译错误。在其他部分中,您应该返回相同类型的数据,例如:
要删除选项,您应该使用getorelse(),
同样,在您的情况下,
输出:
If you want to remove Option in Scala then you can use getOrElse() function.
Scala is a very strong typesafe language which detects compilation errors. In the else part you should return the same type of data, for example:
then to remove Option you should use getOrElse()
Similarly, In your case,
Output :