How are Integer arrays stored internally, in the JVM?

后端 未结 5 818
星月不相逢
星月不相逢 2020-12-20 23:22

An array of ints in java is stored as a block of 32-bit values in memory. How is an array of Integer objects stored? i.e.

int[] vs. Integer[]
5条回答
  •  悲&欢浪女
    2020-12-20 23:56

    It won't be much slower, but because an Integer[] must accept "null" as an entry and int[] doesn't have to, there will be some amount of bookkeeping involved, even if Integer[] is backed by an int[].

    So if every last ounce of performance matters, user int[]

提交回复
热议问题