[jdom-interest] Moving Children

Kevin Baynes kbaynes at seagullsw.com
Fri Jun 15 10:23:19 PDT 2001


Please forgive me for being slow. There is no java.util.List.clone() but
there is a java.util.LinkedList.clone() and ArrayList.clone(). Took me a
while to find that. :-)

So moving children should work like so?:

// Assume creation of two Elements usersA and usersB, each with children
java.util.List       listA = usersA.getChildren();
java.util.List       listB = usersB.getChildren();

java.util.LinkedList cloneList = new LinkedList(listA); // could use
ArrayList also
java.util.LinkedList cloneList = (LinkedList)cloneList.clone(); //shallow
clone, just pointers

listA.clear(); // call clear() to detach children, effectively *moving* them
into cloneList?
listB.addAll(cloneList);
// move is complete

Thanks!

-Kevin

> -----Original Message-----
> From: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]On Behalf Of Jason Hunter
> Sent: Thursday, June 14, 2001 2:51 PM
> To: Kevin Baynes
> Cc: Jason Hunter; Jdom-Interest
> Subject: Re: [jdom-interest] Moving Children
>
>
> > How do I clone the List?
>
> list.clone()
>
> > // Assume creation of two Elements usersA and usersB, each with children
> >
> > Element clone = (Element)usersA.clone();
> >
> > java.util.List listA = clone.getChildren();
> > java.util.List listB = usersB.getChildren();
>
> That clones the element, not the list.  So that's only appropriate if
> you want to copy, not move.  A list clone is fast because it's just a
> raw copy of the element pointers contained within.
>
> -jh-
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/yourad
dr at yourhost.com




More information about the jdom-interest mailing list