【发布时间】:2015-01-01 05:13:39
【问题描述】:
下面的代码可以运行,但我觉得它看起来很奇怪,有没有更好的方法。
var res:scala.collection.mutable.LinkedHashMap[String,scala.collection.immutable.Map[String,String]]=??
var arList = new ArrayList[String]()
res.keySet.map(arList.add(_))
//here res key set changed so i want to reassign the list by new keySet
res=?? //updated
arList.clear
res.keySet.map(arList.add(_))
在arList 上调用.clear 看起来很奇怪
【问题讨论】:
-
您能否详细说明您的实际需求?
-
为什么不使用
res.keySet?为什么需要List? -
@NaderHadjiGhanbari 因为
res.keSet是scala.collection.Set[String]并且我需要java.util.ArrayList[String],我必须将它传递给需要Array List的另一种方法 -
只需使用
toLoist方法然后:res.keySet.toList -
@NaderHadjiGhanbari 它将转换为
List而不是ArrayList
标签: scala collections scala-collections scalastyle