Skip to content

Instantly share code, notes, and snippets.

@tattyamm
Created June 26, 2012 05:46
Show Gist options
  • Save tattyamm/2993573 to your computer and use it in GitHub Desktop.
Save tattyamm/2993573 to your computer and use it in GitHub Desktop.
scalaでsortの練習
case class Hoge(index:Int ,name:String)
object main {
def main(args: Array[String]) {
val hogeList = List(Hoge(0, "hoge1"), Hoge(2, "hoge2"), Hoge(0, "hoge3"), Hoge(0, "hoge6"), Hoge(1, "hoge9"))
println(hogeList)
val hogeListSorted1 = hogeList.sortWith{ (o1,o2)=>
//println(o1,o2)
if (o1.index==o2.index) o1.name > o2.name
else o1.index < o2.index
//o1.index > o2.index
}
val hogeListSorted2 = hogeList.sortBy{
f=>
//println (1.0/f.name(4).toString.toDouble)
f.index + (1.0/f.name(4).toString.toDouble)
}
val hogeListSorted3 = hogeList.sortBy{
_.name
}.reverse
.sortBy{
_.index
}
println(hogeListSorted3)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment