https://kotlinlang.org logo
Title
t

Tuang

12/26/2019, 10:03 AM
hi guys i know how to print all of array element in one line
val topStudents = arrayOf("Jake", "Jesse", "Matt", "Alec")
names.forEach { println(it) }
but how to do in this condition.
val allStudents = setOf {
      "Michael",
      "Kim",
      topStudents <= i don't know how to retrieve topStudent each names likes "Michael" and "Kim" 
}



// the result what i want is 
val allStudents = setOf {
      "Michael",
      "Kim",
      "Jake",
      "Jesse",
      "Matt",
      "Alec"
}
i

Ivan Kubyshkin [JetBrains]

12/26/2019, 10:06 AM
val topStudents = arrayOf("Jake", "Jesse", "Matt", "Alec")

    val allStudents = setOf(
        "Michael",
        "Kim"
    ) + topStudents.toSet()

    allStudents.forEach { println(it) }
t

Tuang

12/26/2019, 10:14 AM
thanks @Ivan Kubyshkin [JetBrains]
b

bezrukov

12/26/2019, 10:23 AM
.toSet()
is not necessary for
topStudents
, it can be just
val allStudents = setOf(
        "Michael",
        "Kim"
    ) + topStudents
👍 1
d

Dico

12/26/2019, 12:20 PM
setOf(
    "Michael",
    "Kim",
    *topStudents
)
5