Does this create one million lists of the 2 same s...
# announcements
r
Does this create one million lists of the 2 same strings or is this optimized somehow? I’m used to declaring such list of accepted values as a
val
before but I’m not sure if it’s needed
Copy code
myListWithOneMillionElements.filter { it.a in listOf("a", "b") }
k
There is currently no optimization for constant lists like in your example. This would create the constant list each time the filter is called for every element in the source list, so in your example a million times. But using
val
is a good solution to this problem.
👍 1