Govind Singh
Govind Singh

Reputation: 15490

Reassign ArrayList in a better Way

The below code is working, but its looking odd to me, is there any better way to this.

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(_))

its looking very odd that to call the .clear on arList

Upvotes: 1

Views: 393

Answers (1)

Eugene Zhulenev
Eugene Zhulenev

Reputation: 9734

You can use default JavaConverters.

  import scala.collection.JavaConverters._
  val list = new java.util.ArrayList(res.keySet.asJavaCollection)

I didn't get why do you need to do clear, is it some requirement that you pass ArrayList once and update it's content later?

Upvotes: 5

Related Questions