Skip to content

Commit d79927b

Browse files
Kotlin Ternary Conditional Operator (eugenp#8427)
* Kotlin Ternary Conditional Operator * moved to package Co-authored-by: Sam Millington <[email protected]>
1 parent 6479ef0 commit d79927b

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

core-kotlin-2/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,10 @@ This module contains articles about core Kotlin.
55
### Relevant articles:
66

77
- [Kotlin Scope Functions](https://www.baeldung.com/kotlin-scope-functions)
8+
- [Kotlin Annotations](https://www.baeldung.com/kotlin-annotations)
9+
- [Split a List into Parts in Kotlin](https://www.baeldung.com/kotlin-split-list-into-parts)
10+
- [String Comparison in Kotlin](https://www.baeldung.com/kotlin-string-comparison)
11+
- [Guide to JVM Platform Annotations in Kotlin](https://www.baeldung.com/kotlin-jvm-annotations)
12+
- [Finding an Element in a List Using Kotlin](https://www.baeldung.com/kotlin-finding-element-in-list)
13+
- [Kotlin Ternary Conditional Operator](https://www.baeldung.com/kotlin-ternary-conditional-operator)
814
- More articles: [[<-- prev]](/core-kotlin)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.baeldung.ternary
2+
3+
import org.junit.Test
4+
import kotlin.test.assertEquals
5+
6+
class TernaryOperatorTest {
7+
8+
@Test
9+
fun `using If`() {
10+
val a = true
11+
val result = if (a) "yes" else "no"
12+
assertEquals("yes", result)
13+
}
14+
15+
@Test
16+
fun `using When`() {
17+
val a = true
18+
val result = when(a) {
19+
true -> "yes"
20+
false -> "no"
21+
}
22+
assertEquals("yes", result)
23+
}
24+
}

0 commit comments

Comments
 (0)