Scala地图密钥由2个逗号分隔组组成。如何在集合中提取第一个键?
我有一个看起来像这样的scala地图集合:
var collection = Map((A,B) -> 1)
键是(a,b),值为1。
我的问题:如果我使用collection.head._1
,结果为(a ,b)正确。但是我想仅提取一个没有b的无需提取,因为我需要将A与其他变量进行比较。因此,最终结果应该存储在不同的变量中。
我尝试使用collection.head._1(0)
导致错误
任何不接受参数
I have a Scala map collection that looks something like this:
var collection = Map((A,B) -> 1)
The key is (A,B) and the value is 1.
My question: If I use collection.head._1
, the result is (A,B) which is correct. But I want to extract A only, without B, as I need to compare A with some other variable. So the final result should be A stored in a different variable.
I tried to use collection.head._1(0)
which results in error
Any does not take parameters
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试:
You can try:
您可以使用
键
将所有键作为set [(String,String)]
,然后map
它进入每个元素的第一个元素:You can use
keySet
to get all the keys as aSet[(String, String)]
and thenmap
it into the first element of each: