kotlin dropWhileメソッドを利用してListから指定した条件の要素を削除する

環境
Ubuntu 22.04.1 LTS
openjdk 11.0.16 8822-07-19
Kotlin version 1.7.88-release-881

構文
List名.dropWhile{条件}
dropWhileメソッドを利用して「List」から指定した条件の要素を削除します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fun main() {
val cft = listOf(13, 42, 53, 64, 75, 86)
println(cft.dropWhile { it < 50 })
println(cft.dropWhile { it < 80 })
println(cft)
}
fun main() { val cft = listOf(13, 42, 53, 64, 75, 86) println(cft.dropWhile { it < 50 }) println(cft.dropWhile { it < 80 }) println(cft) }
fun main() {

    val cft = listOf(13, 42, 53, 64, 75, 86)

    println(cft.dropWhile { it < 50 })
    println(cft.dropWhile { it < 80 })
    println(cft)

}

実行結果
[53, 64, 75, 86]
[86]
[13, 42, 53, 64, 75, 86]

Kotlin

Posted by arkgame