You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you need to check if a list is not empty you can check its size ot use the [isNotEmpty](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/is-not-empty.html) built-in function:
65
+
If you need to check that a list is not empty, you can check its size or use the built-in [isNotEmpty](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/is-not-empty.html) function:
66
66
67
67
```kotlin
68
68
val numbers =listOf(1, 2, 3)
69
69
if (numbers.size !=0) {
70
70
TODO()
71
71
}
72
72
```
73
-
is the **same**with
73
+
It is the **same**as
74
74
75
75
```kotlin
76
76
val numbers =listOf(1, 2, 3)
@@ -82,14 +82,14 @@ is the **same** with
82
82
83
83
<divclass="hint"title="`contains` and `in`">
84
84
85
-
In Kotlin you can use [operators](https://kotlinlang.org/docs/java-interop.html#operators) insted several functions to make code shorter.
85
+
In Kotlin, you can use [operators](https://kotlinlang.org/docs/java-interop.html#operators) insted of several functions to make code shorter.
86
86
For example, instead of the `contains` function, you can use the `in` operator to check if the collection contains some element:
If you need to check that **all** elements match the given predicate, you can use the [`all`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/all.html) built-in function.
103
-
The predicate you need to put into the curly brackets:
102
+
If you need to check that **all** elements match the given predicate, you can use the built-in [`all`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/all.html) function.
103
+
You need to put the predicate in curly brackets:
104
104
105
105
```kotlin
106
106
val evenNumbers =listOf(2, 4, 6)
107
107
println(evenNumbers.all { it %2==0 }) // true
108
-
println(evenNumbers.all { it ==4 }) // false, because only one item satisfies the predicate
108
+
println(evenNumbers.all { it ==4 }) // false because only one item satisfies the predicate
0 commit comments