What's the best way to inverse sort in scala?

前端 未结 9 1832
感情败类
感情败类 2020-12-12 10:11

What is the best way to do an inverse sort in scala? I imagine the following is somewhat slow.

list.sortBy(_.size).reverse

Is there a conv

9条回答
  •  醉酒成梦
    2020-12-12 10:42

    this is my code ;)

    val wordCounts = logData.flatMap(line => line.split(" "))
                            .map(word => (word, 1))
                            .reduceByKey((a, b) => a + b)
    
    wordCounts.sortBy(- _._2).collect()
    

提交回复
热议问题