[jdom-interest] Cost of List / Element
Alex Rosen
arosen at silverstream.com
Sat Jan 12 09:30:20 PST 2002
> Do the getChildren() and get(i) methods above create "heavy" elements
> (populated w/ a lot of String objects) or simply pointers
> into the tree? Is there a better way to do this?
They do not create new objects, they only return the objects already in the
tree.
As far as your sample code goes, you should not cast the return value into a
LinkedList. There's no reason to do this, and it will break with the next
version of JDOM, when the return type changes. (The signature of the
getChildren() method guarantees that the return type is a List, but you
shouldn't assume what kind of List it is.)
Also, it'll be faster if you use an Iterator rather than calling size() and
get() over and over.
Alex
More information about the jdom-interest
mailing list