where is array saved in memory in java?

后端 未结 4 2298
半阙折子戏
半阙折子戏 2021-01-04 08:19

If I have a function that in that function I declare:

Object arr[] = new Object[20];

Where are arr and the whole array stored? heap? stack?

4条回答
  •  忘掉有多难
    2021-01-04 09:01

    An Array of n Strings is

    • A subsequent list of n object references on the heap
    • n single String objects with a reference to an array on the heap
    • n arrays of chars on the heap

    This Array then has a reference as well that can be held on the stack or (as a field on a class) in the heap

提交回复
热议问题