Java eqivalent method of “splice(a,b,…)” in JavaScript method

后端 未结 6 891
伪装坚强ぢ
伪装坚强ぢ 2021-01-20 01:22

someArray.splice(a,b,...) method in JavaScript adds or removes items to/from array. What could be good and simple solution to implement such method in Java lang

6条回答
  •  星月不相逢
    2021-01-20 01:37

    Arrays in Java have a fixed number of elements. But you can make that element null like this:

    array[element]==null;

    And that is the same as removing it from the array. You can also have a variable that keeps track of how many elements aren't null, so that you can even have an array.length kind of thing that follows that. that's what I do anyway.

提交回复
热议问题