How can i declare a list in single line? In groovy i can do something like below
def l = ['a', 'b', 'c'];
What is the kotlin equivalent for this?
You can easily find it in Kotlin documentation :
val list = listOf('a', 'b', 'c')
/** Returns a new read-only list of given elements.
* The returned list is serializable (JVM).
*/
public fun <T> listOf(vararg elements: T): List<T>
= if (elements.size > 0) elements.asList() else emptyList()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.