I'm trying to undersatend how removing elements from ArrayBuffer works. Here is it:
override def remove(n: Int, count: Int) {
if (count < 0) throw new IllegalArgumentException("removing negative number of elements: " + count.toString)
else if (count == 0) return // Did nothing
if (n < 0 || n > size0 - count) throw new IndexOutOfBoundsException("at " + n.toString + " deleting " + count.toString)
copy(n + count, n, size0 - (n + count))
reduceToSize(size0 - count)
}
The thing is copy is implemented as follows:
protected def copy(m: Int, n: Int, len: Int) {
scala.compat.Platform.arraycopy(array, m, array, n, len)
}
It means it just copies the content of the new array to the same array without resizing it. In contrast, ArrayList in JDK resizes array as long as we delete elements from it.
Where is my understanding wrong?