listbuffer

Scala spark, listbuffer is empty

空扰寡人 提交于 2019-12-13 02:35:27
问题 In this piece of code in comment 1 length of listbuffer items is shown correctly, but in the 2nd comment code never executes. Why it is occurs? val conf = new SparkConf().setAppName("app").setMaster("local") val sc = new SparkContext(conf) var wktReader: WKTReader = new WKTReader(); val dataSet = sc.textFile("dataSet.txt") val items = new ListBuffer[String]() dataSet.foreach { e => items += e println("len = " + items.length) //1. here length is ok } println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Update the values of a list with their absolute values

 ̄綄美尐妖づ 提交于 2019-12-13 02:26:06
问题 Newbie to scala. I am trying to make this code to work for a few hours now . It is intended to update the List[Int](list of integers) with absolute values of the integers. Took a long time to figure out that List is immutable, so found that ListBuffer can be the saviour, but eventually in returning it back into the List form is seeing some issue i guess. def f (arr:List[Int]) : List[Int] = { val list = new scala.collection.mutable.ListBuffer[Int](); val len = arr.length; for ( i <- 0 to len)

scala Remove (in place) all elements of a ListBuffer that meet a condition

情到浓时终转凉″ 提交于 2019-12-12 07:44:05
问题 I have a ListBuffer. I want to remove all elements that meet a certain condition. I could iterate over it and remove each element. But what doe Scala say about mutating a list that you are iterating over? Will it work, or will it delete the wrong elements/not return all elements? (A quick attempt with the REPL suggests that yes, it will mess up) I could repeatedly call find and then remove the found element until I don't find any more, but that sounds inefficient. .filter will return me a new

How to create listBuffer in collect function

倖福魔咒の 提交于 2019-12-12 01:18:05
问题 I tought that List is enough but I need to add element to my list. I've tried to put this in ListBuffer constructor but without result. var leavesValues: ListBuffer[Double] = leaves .collect { case leaf: Leaf => leaf.value.toDouble } .toList Later on I'm going to add value to my list so my expected output is mutable list. Solution of Raman Mishra But what if I need to append single value to the end of leavesValues I can reverse but it's not good enough I can use ListBuffer like below but I

Scala spark, listbuffer is empty

假如想象 提交于 2019-11-26 12:32:53
In this piece of code in comment 1 length of listbuffer items is shown correctly, but in the 2nd comment code never executes. Why it is occurs? val conf = new SparkConf().setAppName("app").setMaster("local") val sc = new SparkContext(conf) var wktReader: WKTReader = new WKTReader(); val dataSet = sc.textFile("dataSet.txt") val items = new ListBuffer[String]() dataSet.foreach { e => items += e println("len = " + items.length) //1. here length is ok } println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") items.foreach { x => print(x)} //2. this code doesn't be executed Logs are here: 16/11/20 01:16:52

Scala spark, listbuffer is empty

无人久伴 提交于 2019-11-26 04:02:15
问题 In this piece of code in comment 1 length of listbuffer items is shown correctly, but in the 2nd comment code never executes. Why it is occurs? val conf = new SparkConf().setAppName(\"app\").setMaster(\"local\") val sc = new SparkContext(conf) var wktReader: WKTReader = new WKTReader(); val dataSet = sc.textFile(\"dataSet.txt\") val items = new ListBuffer[String]() dataSet.foreach { e => items += e println(\"len = \" + items.length) //1. here length is ok } println(\"!!!!!!!!!!!!!!!!!!!!!!!!!