Domanda

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.

È stato utile?

Soluzione

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]
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top