Integer vs int: with regard to memory

前端 未结 4 1055
春和景丽
春和景丽 2020-11-28 08:45

I was wondering if there is a difference in the memory occupied by Integer n, and int n.

I know int n occupies 4 bytes normal

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-28 09:21

    An Integer object in Java occupies 16 bytes.

    I don't know whether running a 64- vs 32-bit JVM makes a difference. For primitive types, it does not matter. But I can not say for certain how the memory footprint of an object changes (if at all) under a 64-bit system.

    You can test this for yourself here:

    Java Tip 130: Do you know your data size?

提交回复
热议问题