[jdom-interest] How do add a child?

Ken Rune Helland kenh at csc.no
Tue Nov 13 01:53:01 PST 2001


> Kevin,
> 
> Look at the Element javadoc, specifically the
> overloaded addContent(...) methods
> 
[SNIP]
>  --- kevin.schmidt at convergys.com wrote: > 
[SNIP]
>> List childs = elem1.getChildren();
>> childs.add(elem2);
>> elem1.setChildren(childs);

Also the list returned by Element.getChildren is a live list
so changing this list changes the Element. so the last step is
not nessesary. You coud write this:

elem1.getChildren().add(elem2);

But still, if you are just appending at the end of the list
the addContent(...) are the simplest and probably most efficient
as the getChildren metod generates a wraper list object around the
internal list.


KenR







More information about the jdom-interest mailing list