kotlin Listの要素に指定した条件を満たすものがあるかを判定する

kotlinで、Listの要素に指定した条件を満たすものがあるかを判定する手順を記述してます。
環境
- OS windows11 home
- java 17.0.2
- kotlin 1.6.10-release-923
手順
kotlinで、Listの要素に指定した条件を満たすものがあるかを判定するには、「none」で可能です。
List名.none { 条件 }
実際に、使用してみます。
fun main() {
val list = listOf(10, 20, 30, 40, 50, 60)
println(list.none { it > 65 })
// true
println(list.none { it > 55 })
// false
}
判定されていることが確認できます。
mutableList
「mutableList」にも使用可能です。
fun main() {
val list = mutableListOf(10, 20, 30, 40, 50, 60)
println(list.none { it > 65 })
// true
println(list.none { it > 55 })
// false
}
-
前の記事
GAS スプレッドシートの行を非表示にする 2022.09.28
-
次の記事
kotlin エラー「error: class ‘xxx’ is not abstract and does not implement abstract base class member public abstract fun x(): Unit defined in xxx」の解決方法 2022.09.28
コメントを書く