Re: Please review this code: ArrayList clone
On Thu, 17 Dec 2009, guptan wrote:
Please review this code as my platform doesnot have array list but
only slow vector.
http://pastesite.com/12249
Hoping to hear your valuable suggestions.
Stop, drop, and use this instead:
http://backport-jsr166.sourceforge.net/index.php
It doesn't have your shrink method, but you can easily add that
externally:
void shrink(List l) {
Iterator it = l.iterator();
while (it.hasNext()) {
if (it.next() == null) it.remove();
}
}
That has the same effect at the array level as your shrink method, which
as you observe is rather inefficient. You can do better with a loop doing
get/set at a pair of advancing indices, but i leave this as an exercise to
the reader.
tom
--
I was eventually persuaded of the need to design programming notations
so as to maximize the number of errors which cannot be made, or if made,
can be reliably detected at compile time. Perhaps this would make the
text of programs longer. Never mind! Wouldnt you be delighted if your
Fairy Godmother offered to wave her wand over your program to remove
all its errors and only made the condition that you should write out
and key in your whole program three times! -- C. A. R, Hoare