Back to questions
JuniorTheoryCommon
What does the program print?
fun main() {
val words = listOf("b", "a", "b", "c", "a")
println(words.toSet())
}[b, a, c]
- Expecting
[a, b, c]:toSet()does not sort. It keeps each word where it first appeared, sobstays ahead ofa. - Expecting a repeated word to disappear completely: a set drops only the extra copies and keeps one of each, so
bandaare still there.
- What does
words.toSet().sizeprint, and how does it compare withwords.size? - Which call would print the words in alphabetical order without repeats?