Created
June 26, 2012 05:46
-
-
Save tattyamm/2993573 to your computer and use it in GitHub Desktop.
scalaでsortの練習
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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