[jdom-interest] List's in JDOM - a small essay

Ken Rune Helland kenh at csc.no
Fri Mar 9 09:51:22 PST 2001

At 08:57 AM 3/9/2001 -0800, Jason Hunter wrote:
> > I agree, if you commondly (almost always) insert at
> > the back of the list you must have a lastItem reference.
>The list will cache the last element so add's are fast.  But that last
>element won't hold a ptr to the previous element, so you can't iterate
>Using a singly linked list saves quite a lot of memory and actually from
>prelim testing makes the add() operation twice as fast (due to fewer
>pointer manipulations).  Personally, think a singly linked list is a
>good idea because of these benefits and the fact I've never needed to
>iterate a list backward.  If you've found need to iterate a list
>backward, please follow up to this post and explain why.

I dont have a usecase for travesing the whole list backvards,
but i have a case where i want to remove an element, and
then i want to check if the previus and next elements are
Strings that ends and begins with "\n" in that case i want to
cut the "\n" from the end of the previus entry or the
begining of the next. or if one of them is only "\n" I
want to remove it altogeter.

Actually, for my purposes it woud be better to have a
trim option on the builder that removed newlines between
Elements and just reset them in the outputter.

Anyway, the Iterator and ListIterators remove() and set()
metods means at least the iterators must keep a reference
to the previus item. And it shoud be put in the doc
that the ListIterator.Previus() metod will be wery slow
and its usage is discurraged.

But now am late and i REALLY have leave.

Best Regards


More information about the jdom-interest mailing list