append values dynamically into an long[] array

后端 未结 5 938
忘了有多久
忘了有多久 2020-12-20 20:44

i need some help regarding adding values into an array

for example

long[] s = new long[] {0, 1, 2};

when i do this i instantiate an

5条回答
  •  悲&欢浪女
    2020-12-20 21:38

    You cannot append values to array dynamically as the memory space is allocated to array object at the time of initializing, it means pre defined consecutive memory location is allocated.Hence we need to use array list because it uses linked list data structure internally and allows you to add/remove/sort easily without wasting any memory space.

提交回复
热议问题