This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

merging two lists inside a list

 
mohd sheriff
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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]]
also
[[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.

Thanks

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check your private messages for important administrative matters.
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a method in the ArrayList API that allows you to add a Collection to the ArrayList, you can sort after that.

Hunter.
 
Artur Lorincz
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 )

Artur
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic