Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
get the sublist of object for particular date
vivek dhiman
Ranch Hand
Posts: 157
I like...
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi
I am looking to get the sublist from a list of objects as per date enter. Objects that are added in the list (partyList) has the property of type Date. Below is my method, but not able to figure it out, how can i get the sublist.
public void listAllPartiesDayWise() { System.out.println(" Inside List All Parties - Date Wise"); System.out.println(" Enter the time for the party in format yyyy-MM-dd HH:mm "); List<RegisterParty> partyListDateWise = new ArrayList<>(); Scanner scanner = new Scanner(System.in); String date = scanner.nextLine(); Date date1 = helperFunctions.convertToDate(date); List<RegisterParty> partyList = listAllParties(false); for (int i = 0; i < partyList.size(); i++) { RegisterParty registerParty1 = partyList.get(0); // want to find the objects which has date as per the date1 // All RegisterParty objects has the property **dateOfParty** } }
Any idea how can in achieve it.
Thanks
Campbell Ritchie
Marshal
Posts: 79177
377
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
In Java8 you would do something like
List<Party> sublist = myList.stream() .filterBy(Party::getDate.equals(new Date("30th April 2015"))) .collect(Collectors.toList());
And if that compiles I shall be very surprised! If you look in the
Stream documentation
you should
find hints to get something which actually works.
Campbell Ritchie
Marshal
Posts: 79177
377
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Go through the
Java® Tutorials
about new date classes, and stop using Date.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Command-Line arguments
Code review required for converting dateformat
Date format related question
Manual Calendar
testing a date class
More...