2

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.

Roman C
  • 48,723
  • 33
  • 63
  • 158
Rollerball
  • 11,792
  • 22
  • 89
  • 148
  • Can you give an example of a List which does this? – Peter Lawrey Jul 27 '13 at 08:25
  • @PeterLawrey ArrayList implementation of List has that method. I was just curious why it's not present the same in the concurrent version.. maybe due some synchronization issues? I know how to workaround it. thanks – Rollerball Jul 27 '13 at 08:32
  • If any interested in the thing, check this out: http://stackoverflow.com/questions/2289183/why-is-javas-abstractlists-removerange-method-protected – Rollerball Jul 27 '13 at 08:45

1 Answers1

4

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]
Peter Lawrey
  • 513,304
  • 74
  • 731
  • 1,106