4 Replies Latest reply on Jan 2, 2008 12:02 PM by 2JZ

    Merging 2 ArrayCollection lists ( not concat.)!

    2JZ Level 1
      Hi all,

      I am trying to merge two ArrayCollection lists with structure below:

      1) .
      L(item1)
      L(sub-item1a)
      L(item2)
      L(sub-item2a)
      L(item3)
      L(sub-item3a)

      2) .
      L(item1)
      L(sub-item1b)
      L(item2)
      L(sub-item2b)
      L(item3)
      L(sub-item3b)


      And, I want the result to become as follow:
      3) .
      L(item1)
      L(sub-item1a)
      L(sub-item1b)
      L(item2)
      L(sub-item2a)
      L(sub-item2b)
      L(item3)
      L(sub-item3a)
      L(sub-item3b)

      Is this possible? How can I do this? Please help!
        • 1. Re: Merging 2 ArrayCollection lists ( not concat.)!
          atta707 Level 2
          Are the elements in both the array collection unique? If so, isn't it a simple case of adding all the elements of AC into another and sort the resultant AC?

          ATTA
          • 2. Re: Merging 2 ArrayCollection lists ( not concat.)!
            2JZ Level 1
            I think the post function takes out the whitespace. Let me rephrase my question abit.

            1) .
            L(item1)
            .....L(sub-item1a)
            L(item2)
            .....L(sub-item2a)
            L(item3)
            .....L(sub-item3a)

            2) .
            L(item1)
            .....L(sub-item1b)
            L(item2)
            .....L(sub-item2b)
            L(item3)
            .....L(sub-item3b)


            And, I want the result to become as follow:
            3) .
            L(item1)
            .....L(sub-item1a)
            .....L(sub-item1b)
            L(item2)
            .....L(sub-item2a)
            .....L(sub-item2b)
            L(item3)
            .....L(sub-item3a)
            .....L(sub-item3b)

            The lsit 1 & 2 has the same tag. However, the sub-tags are different. All I want is to merge all the sub-items into the parent. Hope I can make my question clear.
            • 3. Re: Merging 2 ArrayCollection lists ( not concat.)!
              paulfeuer Level 1
              atta is correct i think. unless, that is, your array collection has members that are hierarchical. if that's the case, it sounds like perhaps your array collections that you mention above each have 3 members. the way you describe them above, i originally assumed they had 6 members and the result ArrayCollection had 9.

              to get the result you want, you have to iterate thru both and join them up. i don't think there's anything that will magically do that. to help, you might consider using an object as a map to reduce the number of iterations you do.

              ./paul

              • 4. Re: Merging 2 ArrayCollection lists ( not concat.)!
                2JZ Level 1
                Okie. So, I guess there is no quick way to merge them. In order to do so, I'll need to create a new ArrayCollection and new objects. Create new objects that contains both attributes/sub-items (under different lists) then add it to the new ArrayCollection?

                Thanks for the reply.