javaarraysconcurrencycopyonwritearraylist

Why is there no such removeRange() method in CopyOnWriteArrayList?


Why in the ArrayList there is such a method and on the concurrent sibling there is not?

protected void removeRange(int fromIndex, int toIndex)

Just curious about it it's not fundamental I can workaround it.


Solution

  • You can do this indirectly.

    List<Integer> ints = new CopyOnWriteArrayList<Integer>();
    for (int i = 0; i < 10; i++) ints.add(i);
    ints.subList(4, 7).clear();
    System.out.println(ints);
    

    prints

    [0, 1, 2, 3, 7, 8, 9]