split과 동시에 assign

Kotlin|2021. 11. 29. 21:02

 

val text = "a,b"
val (one,two) = text.split(",")
/*
val one = text.split(",")[0]
val two = text.split(",")[1]
*/

 

코드 작성중 신기하고 편리해보이는 문법

까먹지 않기 위해 기록

 

text.split(",")의 size가 2보다 크더라도 [0], [1] 만 assign되지만

size가 2보다 작으면 IndexOutOfBoundsException 발생함

 

댓글()