2019年4月22日月曜日

開発環境

Head First Kotlin: A Brain-Friendly Guide (Dawn Griffiths(著)、David Griffiths(著)、O'Reilly Media)のChapter 9(collections - Get Organized)、Mixed Messages(285)の解答を求めてみる。

コード

fun main() {
    val mList = mutableListOf("Football", "Baseball", "Basketball")

    mList.sort()
    println(mList == mutableListOf("Baseball", "Basketball", "Football"))

    val mMap = mutableMapOf("0" to "Neball")
    val x = 0
    for (item in mList) {
        mMap.put(x.toString(), item)
    }
    println(mMap.values.toList() == listOf("Football"))

    mList.addAll(mList)
    mList.reverse()
    val set = mList.toSet()
    println(set == setOf("Football", "Baseball", "Basketball"))

    val mList1 = mutableListOf("Football", "Baseball", "Basketball")
    mList1.sort()
    mList1.reverse()
    println(mList1 == mutableListOf("Football", "Basketball", "Baseball"))
}

入出力結果

true
true
true
true

Process finished with exit code 0

0 コメント:

コメントを投稿