Hullaballoonatic
03/08/2020, 5:11 PMmyList.toArray { it + 1 }
v
myList.map { it + 1 }.toArray()
to be precise, I'm wondering if Kotlin performs equally well, not simply that they have the same runtime complexity.Kroppeb
03/08/2020, 5:28 PMmap
return a list?Dico
03/08/2020, 5:29 PMHullaballoonatic
03/08/2020, 5:30 PMIterable<int>
in this case, but I might be wrong (been writing too much c#). Not really the point, but touche.Dico
03/08/2020, 5:30 PMDico
03/08/2020, 5:31 PMKroppeb
03/08/2020, 5:43 PMtoArray
doesn't use an intermediate so it's faster.
However once the JIT desides to optimise it, it becomes hard to see if there is any difference. If you use graalVM I think it's the same, but the standard JVM is most likely a tad slower for the map{}.toArray
caseHullaballoonatic
03/08/2020, 6:28 PMDico
03/08/2020, 7:07 PME.Kisaragi
03/16/2020, 6:53 AM