[jdom-interest] Cost of List / Element
Ron Chibnik
ron at chibnik.com
Thu Jan 10 13:21:00 PST 2002
Forgive me if this is a basic question - I couldnt find anything in the
archives. In fact, it may actually be a basic Java question, but here goes.
What is the cost of this type of code (the value of the supplied tag for a
given fund allocation):
// Get the value for the supplied tag for the supplied fund
public String getAllocationValue(String fundNum, String tag) {
LinkedList fundAllocations = (LinkedList)
doc.getRootElement().getChildren(FundAllocation_TAG);
for (int i=0;i<fundAllocations.size();i++) {
Element elt = (Element) fundAllocations.get(i);
if (elt.getChildTextTrim(FundNumber_TAG).equals(fundNum))
return elt.getChildTextTrim(tag);
}
return null;
}
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?
Also, is there a better way to search through a document than this
sequential search? I expect to have the list sorted, so conceivably I could
do a binary search. In most cases my tree is small, so sequential search is
ok (improvements would not be worth additional code) but there could be
times when I have 5000 elements to sift through.
Thanks in advance for your input.
More information about the jdom-interest
mailing list