I am new in Java and Kotlin.
Recently when I read a tutorial while learning Kotlin.
I found there are some Array/List confusing me.
- What is the different between
ArrayList,IntArrayandArray<Int>? - When should I use them?
I am new in Java and Kotlin.
Recently when I read a tutorial while learning Kotlin.
I found there are some Array/List confusing me.
ArrayList, IntArray and Array<Int>?Major differences
ArrayList : resizable, Generic (Objects)
IntArray : primitive, fix length, only Int values
Array<Int> : Generic (Objects), fix length
I see multiples questions inside of your question and i gonna attempt to help you.
ArrayList and List:Array is static in size, ArrayList is autoresizable.ArrayList can not contains primitive types (like int, char, ...), List can.Array<Int> and IntArrayCheck this question who respond to this question: IntArray vs Array<Int> in Kotlin
but in summary:
Array<Int> == Integer[]
IntArray == int[]
That's it !
This will partially answer your question: Difference between List and Array types in Kotlin
Besides, the difference between IntArray and Array<Int> is the same as between Java int[] and Integer[]: the former stores primitive integers without wrapping them while the latter boxes them into java.lang.Integer objects. Consider IntArray an optimized form of Array<Int> that does not introduce memory and boxing-unboxing overheads.