Scala List的排序函数sortWith

//原始方法:

//val list=List("abc","bcd","cde")

scala> list.sortWith( (s,t) => s.compareTo(t) <0 )

res1: List[String] = List(abc,bcd,cde)

//匿名方法:

scala> list.sortWith( _.compareTo(_) <0 )

res2: List[String] = List(abc,bcd,cde)

//上述为字典序递增,若递减则改'<'为'>'即可


 

你可能感兴趣的:(scala)