sortBy()

定义:

def sortBy[B](fun: (A) =>B)

栗子1:

val words = "the quick brown fox jumped over the lazy dog"

val words_split = words.split(" ")

words_split.sortBy(x =>(x.length, x.head) )  // 按照右边的(x.length, x.head)进行排序

output:  The, dog, fox, the, lazy, over, brown, quick, jumped

栗子2:

val myseq1 = Array((3,1,2,5),(2,4,5,1),(8, 2, 4,9)

myseq1.sortBy(_._1).foreach(println)

05-11 19:26