Java find last member in index of array

前端 未结 2 1506
耶瑟儿~
耶瑟儿~ 2021-01-27 03:51

So let say I have an array of size 10 with index range from 0 to 9. I add a bunch of elements in and stop adding at index 6. So with array.length, I can know that the size of th

2条回答
  •  攒了一身酷
    2021-01-27 03:56

    Use java.util.ArrayList. There you no need to think about index and it is resizable-array implementation.

    At the time of array creation by default all values are null so if you do not insert any value at any index (may be at end or beginning or middle of array) it would be just null. So you should put null check to verify.

提交回复
热议问题