This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val jane = User("Jane", 35) | |
val (name, age) = jane // 구조 분해 | |
println("$name, $age세") // Jane, 35세 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val jack = User(name = "Jack", age = 1) | |
val olderJack = jack.copy(age = 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Person(val name: String) { | |
var age: Int = 0 | |
} | |
fun main() { | |
val person1 = Person("John") | |
val person2 = Person("John") | |
person1.age = 10 | |
person2.age = 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Person(val name: String) { | |
var age: Int = 0 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val rectangle = Rectangle(5.0, 2.0) | |
val triangle = Triangle(3.0, 4.0, 5.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
val fruits = listOf("banana", "avocado", "apple", "kiwifruit") | |
fruits | |
.filter { it.startsWith("a") } | |
.sortedBy { it } | |
.map { it.toUpperCase() } | |
.forEach{ println(it) } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
val items = setOf("apple", "banana", "kiwifruit") | |
when { | |
"orange" in items -> println("juicy") | |
"apple" in items -> println("apple is fine too") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
val items = listOf("apple", "banana", "kiwifruit") | |
for (item in items) { | |
println(item) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
for (x in 1..10 step 2) { | |
print(x) //13579 | |
} | |
println() | |
for (x in 9 downTo 0 step 3) { | |
print(x) //9630 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
for (x in 1..5) { | |
print(x) | |
} | |
} |
NewerOlder