3

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.

  1. What is the different between ArrayList, IntArray and Array<Int>?
  2. When should I use them?
3
  • On the java side there is the fixed sized array: int[] (with the primitive type int) and dynamically sized ArrayList<Integer> (with the int wrapper Integer). Commented Jan 17, 2018 at 15:51
  • 1
    This question basically duplicates two other questions: (1) Difference between List and Array types in Kotlin and (2) IntArray vs Array<Int> in Kotlin Commented Jan 17, 2018 at 15:57
  • @hotkey alright. thank you for pointing it out. Commented Jan 17, 2018 at 16:09

3 Answers 3

4

Major differences

ArrayList : resizable, Generic (Objects)

IntArray : primitive, fix length, only Int values

Array<Int> : Generic (Objects), fix length

Sign up to request clarification or add additional context in comments.

Comments

3

I see multiples questions inside of your question and i gonna attempt to help you.

First question: What is the difference between ArrayList and List:

  • Array is static in size, ArrayList is autoresizable.
  • ArrayList can not contains primitive types (like int, char, ...), List can.

Second question: What is the difference between Array<Int> and IntArray

Check this question who respond to this question: IntArray vs Array<Int> in Kotlin

but in summary:

Array<Int> == Integer[] 
IntArray == int[]

That's it !

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.