This week's book giveaway is in the JDBC and Relational Databases forum.
We're giving away four copies of Resilient Oracle PL/SQL: Building Resilient Database Solutions for Continuous Operation and have Stephen Morris on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

How to crate Multiple ArrayList from one ArrayList

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 27667
89
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 27667
89
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Jay Vaghela
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Self destruct mode activated. Instructions for deactivation encoded in this tiny ad.
Master Gardener Program
https://coderanch.com/t/771761/Master-Gardener-Program
reply
    Bookmark Topic Watch Topic
  • New Topic