Forums Register Login

How to add multple lists in one list in insertion order

+Pie Number of slices to send: Send
Hi,

I want to add the list elements from multiple lists to one parent list. Can some some tell me how it can be done?
e.g.



I want the following in the output parent list
ParentList:[12,323,11,43,1,87]

Please help..
+Pie Number of slices to send: Send
Collection, and therefore also List, has a method called addAll to add all elements of any other collection in one go. For List, addAll will add all those elements at the end. So just create a new List, and call addAll for all Lists whose contents need to be added.
+Pie Number of slices to send: Send
Just create the empty parentlist, then addAll the lists you wish.

Eg:

+Pie Number of slices to send: Send
. . . and Lists retain insertion order as a default behaviour. You would have to look in the documentation for addAll to see which order it adds in. It says in the Java™ Tutorials that addAll concatenates Lists.
+Pie Number of slices to send: Send
Ahh! It was so quick and easy.

Thank you all
+Pie Number of slices to send: Send
You're welcome

You spend hours and hours designing the List classes, and once you have got them working, they become really easy to use.
Clowns were never meant to be THAT big! We must destroy it with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1394 times.
Similar Threads
Iterating an arrayList Inside iteration of the other arrayList
Iterating an arrayList Inside iteration of the other arrayList
How can I manually add values to ArrayList[]
Why generic wildcard could bypass the type safety?
How to remove common item between 2 ArrayList
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:08:08.