If you are trying to transform a List structure that implements RandomAccess (e.g. ArrayList or Array ), you can use this version for better performance:
IntArray(strings.size) { strings[it].toInt() }
This version is compiled for the base loop and int[] :
int size = strings.size(); int[] result = new int[size]; int index = 0; for(int newLength = result.length; index < newLength; ++index) { String numberRaw = strings.get(index); int parsedNumber = Integer.parseInt(numberRaw); result[index] = parsedNumber; }
Yoav sternberg
source share