p.s. .sdrawkcab si od I gnihtyreve os cibaraA tuoba gnikniht neeb evah I.
On Sun, Jan 10, 2010 at 4:38 PM, Ted Dunning <[email protected]> wrote: > I take it that the point of this code is to allow filling an ArrayList with > null values efficiently. This might sometimes be useful, I suppose. > > It sounds like you are saying that the virtue of the ObjectArrayList is that > we own it and can make this resizing method efficient. I don't see any > advantage of that strategy versus forking some other implementation or even > starting a new implementation from scratch. I am also not clear on the > virtues of this resizing in general. In particular, the idiom > > if (l.size() > size) l.sublist(size, l.size() - size).clear() > > seems a better way to clear a bunch of values. Collections.fill() applied > to a sublist should be good as well. > > If you just need to fill in an ArrayList quickly to a desired size, then > addAll from a static list of nulls could be a bit faster. Is speed really > important here, though? > > As a side note, the tests in your code appear to be backwards. > > On Sun, Jan 10, 2010 at 12:17 PM, Benson Margulies > <[email protected]>wrote: > >> Colt brought us 'ObjectArrayList'. You might ask, what advantage does >> it have over ArrayList<T>? >> >> Well, I just found myself writing the following to use ArrayList<T> in >> the xxxObjectHashMap set. I could rework ObjectArrayList to be a >> subclass of ArrayList that provided this efficiently, instead of my >> current plan to throw it out altogether once I've got other things >> cleaned up. Thoughts? >> >> private void resizeArrayList(ArrayList<T> l, int size) { >> while (size < l.size()) { >> l.add(null); >> } >> while(size > l.size()) { >> l.remove(l.size()-1); >> } >> } >> > > > > -- > Ted Dunning, CTO > DeepDyve >
