File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to crate Multiple ArrayList from one ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to crate Multiple ArrayList from one ArrayList" Watch "How to crate Multiple ArrayList from one ArrayList" New topic
Author

How to crate Multiple ArrayList from one ArrayList

Jay Vaghela
Greenhorn

Joined: Feb 15, 2006
Posts: 22
I have an ArrayList called


The Bean FormBean contains a Date field, the value of the date can be different.


Now, based on the joining date I want to create multiple ArryaList.
Like


So if there are 3 different dates then I want to create three ArrayList.
Please advice me how to create that list.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

But it's not 3, right? It's "multiple"? So how do you want to store these "multiple" array lists? You can't start programming until you decide what your code is supposed to do.
Jay Vaghela
Greenhorn

Joined: Feb 15, 2006
Posts: 22
The number of JoiningDate is fixed to 3, (I gave it just an example, but the number of multiple arraylist is fixed to 3)
So I will store them in new ArrayList
Jay Vaghela
Greenhorn

Joined: Feb 15, 2006
Posts: 22
I want to know what condition I should put inside the loop


Also, I have override the equal method based on the joiningDate
Jay Vaghela
Greenhorn

Joined: Feb 15, 2006
Posts: 22
Thanks Paul,
Ok, So, instead of joiningDate just consider it this way, if a person allowed to marry only 3 times in a life then his marriage date would be maximum 3.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Jay Vaghela
Greenhorn

Joined: Feb 15, 2006
Posts: 22
firstDate is an ArrayList and form.getJoiningDate is a type of Date.
I can use .contains() method but not sure the exact way.
because how to add the first element in firstDate ArrayList?
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
How about something like:


It might be more flexible if requirements change in the future.


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Jay Vaghela
Greenhorn

Joined: Feb 15, 2006
Posts: 22
Sorry, but not getting what you mean to say.
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
The groupByDate() method takes a List<FormBean> and returns a Map<Date, List<FormBean>>, you can use this data structure as-is or optionally transform it into a List<List<FormBean>> where every element in each sub-list has the same Date.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to crate Multiple ArrayList from one ArrayList