https://kotlinlang.org logo
#getting-started
Title
# getting-started
t

Tech

03/24/2023, 6:56 PM
Hey I was wondering how I could add two lists together like this
Copy code
val list1 = listOf("hello", "world")
val list2 = listOf(*list1, "test")
I mainly just need to spread list1 into list2 so the type is List<String> on list2
e

ephemient

03/24/2023, 6:58 PM
Copy code
listOf(*list1.toTypedArray(), "test")
but don't do that, because
Copy code
list1 + "test"
is clearer
t

Tech

03/24/2023, 6:58 PM
Ah thank you so much.
3 Views