Can I ask?
# announcements
a
Can I ask?
g
just ask
a
What's the difference between
ArrayList<Int>
,
Array<Int>
and
IntArray
?
c
@Ayden
IntArray
is a more optimized version of
Array<Int>
. Both are arrays.
ArrayList<Int>
is a list backed by an array.
If you're not sure which one to use, use
listOf()
(or
arrayListOf()
if you need a mutable list)
s
A good way I found to figure these things out is to write these things in Intellij and then use the
Show Kotlin Bytecode
action. You can then Hit the Decompile button and see the Java equivalent of your Kotlin code to see the result yourself
g
Array<Int> contains objects with type Int, IntArray contains primitive 32-bit Int values
s
So for a class like this
Copy code
class Arr(val a1: Array<Int>,
          val a2: ArrayList<Int>,
          val a3: IntArray)
The decompiled kotlin bytecode will look like
Copy code
.....
   @NotNull
   private final Integer[] a1;
   @NotNull
   private final ArrayList a2;
   @NotNull
   private final int[] a3;
...
❤️ 1
a
Thanks everyone.
Just back from lunch.
s
you may find #C0B8MA7FA useful
a
What the context for these 3?
@Shawn mean I ask in the wrong channel? 😞
s
I mean, you’re not posting in the wrong channel, but you might get better help in the other one