Fast algorithm to remove a number of elements from an ArrayList

前端 未结 4 1325
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-19 18:38

Say an ArrayList is of size n.

In my case, I often need to remove from 1 to n elements with different indexes from an ArrayList.

By using visualvm profiler,

4条回答
  •  余生分开走
    2021-01-19 19:14

    ArrayList is not really a good data structure to do this operation.

    I would suggest you to use the HashMap for this purpose, you can keep the key, value pair with the key as the indexes.

提交回复
热议问题