Nuz reel
Nuz reel

Reputation: 19

Sort tuple ListBuffer

So i have this ListBuffer with 2 values: String and BigDecimal, after populate my List i want to sort it before print:

var data = new ListBuffer[(String, BigDecimal)]
data+=(("se", 34))
data+=(("sh", 4))
data+=(("fjd", 33))
data+=(("dhdh", 24))
data+=(("dhd", 125))

And i wonder how to sort this according BigDecimal value so this is what i have try:

val list = data.map(x=>x._2 > x._2)

Upvotes: 0

Views: 169

Answers (1)

Sleiman Jneidi
Sleiman Jneidi

Reputation: 23329

You can use sortBy and use the ordering of the value of the second element as following,

data = data.sortBy(_._2)

Upvotes: 0

Related Questions