yangyuexiang wrote:
>
> > Hi, Everyone
>
> This is an interesting problem.
>
> I add a list of nodes into a group.
>
> eg. suppose lst has n elements and then
>
> for(Iterator iter = lst.iterator; iter.hasNext(); )
> {
> group.addChild((Node)(iter.next()));
> }
>
> Then the two elements: o1 and o2 are different:
>
> o1 = group.getChild(n-1);
> o2 = lst.get(n-1);
>
> Why???
You are assuming that the lst.iterator is returning objects in the
same order in which they were added to the list originally.
I don't think Iterator makes this promise for all types of
collections. You don't say if lst is a LinkedList, or some other
type of Set.
What if group already contained elements? Your count would definately
be off in that case.
--
Joi Ellis Software Engineer
Aravox Technologies [EMAIL PROTECTED], [EMAIL PROTECTED]
No matter what we think of Linux versus FreeBSD, etc., the one thing I
really like about Linux is that it has Microsoft worried. Anything
that kicks a monopoly in the pants has got to be good for something.
- Chris Johnson
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]