is it uncommon to use primitive array types (IntAr...
# codingconventions
f
is it uncommon to use primitive array types (IntArray, BooleanArray etc) in Kotlin?
g
As it was said, it's depends on your usecase, but in general because arrays are pretty limited in many aspects it's much more common to use List instead, and use arrays as performance optimization in some cases and usually do not expose it in public API
f
Thank you
Leaving the primitive variations aside, is Integer[] faster than ArrayList<Integer>?
g
Integer[] is boxed, non-primitive array, so ArrayList<Integer> would be very close by performance, you just pay price of additional object But int[] (or Kotlin IntArray) is better in terms of memory and allocation (get/set complexity is the same as List<Int>)
f
I'm just trying to figure out what the point of Array<> is
when it's worse in pretty much every point
g
Array<T> is just a platform primitive (part of memory with references to other objects), for example point of it to implement other, higher level collections, ArrayList (and many other data structures) are based on generic array
And this is cause quite rare usage of it. But it's still useful, after all you need some efficient way to keep list of references to other objects, but mostly it make sense for library authors
f
I see, thanks for the explanation