File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes merging two lists inside a list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "merging two lists inside a list" Watch "merging two lists inside a list" New topic

merging two lists inside a list

mohd sheriff

Joined: Apr 14, 2009
Posts: 1
hi all,
i want to merge two lists inside a list
[] --> ArrayList
c1,c2,c3,c4,c5 --> different objects of the same class (eg. some customer class)

merging criteria::

[[c1,c2],[c3,c4],[c1,c5]] to [[c1,c2,c5],[c3,c4]]
[[c1,c2],[c2,c3],[c3,c4]] to [[c1,c2,c3,c4]]

Thing is, its like lists inside a list.

Hope you can help me implementing this.


Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63867

Please check your private messages for important administrative matters.

[Asking smart questions] [About Bear] [Books by Bear]
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

There is a method in the ArrayList API that allows you to add a Collection to the ArrayList, you can sort after that.


"If the facts don't fit the theory, get new facts" --Albert Einstein
Artur Lorincz

Joined: Jun 30, 2003
Posts: 2
Assuming that you already have the list of lists structure, what you need to do is to figure out:
1. How to traverse this structure
2. How to combine the lists that should be merged (See the hint from the previous post)
3. How to collect the merged lists into the final list (If you managed to build up the list of lists structure this is done )

I agree. Here's the link:
subject: merging two lists inside a list
It's not a secret anymore!