Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to crate Multiple ArrayList from one ArrayList

 
Jay Vaghela
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20955
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20955
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Jay Vaghela
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about something like:


It might be more flexible if requirements change in the future.
 
Jay Vaghela
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, but not getting what you mean to say.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic