Question
import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.GregorianCalendar; import java.util.List; import java.util.ListIterator; public class CollectionsProblem { public static void main(String[] args) { ArrayList
import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.GregorianCalendar; import java.util.List; import java.util.ListIterator; public class CollectionsProblem { public static void main(String[] args) { ArrayList list1 = new ArrayList(); ArrayList list2 = new ArrayList(); list1.add(new GregorianCalendar(1920, 0, 1)); // note month 0 is January, java counts funny list1.add(new GregorianCalendar(1930, 0, 1)); list1.add(new GregorianCalendar(1940, 0, 1)); list1.add(new GregorianCalendar(1950, 0, 1)); list1.add(new GregorianCalendar(1960, 0, 1)); list1.add(new GregorianCalendar(1970, 0, 1)); list1.add(new GregorianCalendar(2001, 1, 28)); // and month 1 is February! list2.add(new GregorianCalendar(1925, 0, 1)); // note month 0 is January, again list2.add(new GregorianCalendar(1935, 0, 1)); list2.add(new GregorianCalendar(1945, 0, 1)); list2.add(new GregorianCalendar(1955, 0, 1)); list2.add(new GregorianCalendar(1965, 0, 1)); list2.add(new GregorianCalendar(1975, 0, 1)); list2.add(new GregorianCalendar(2001, 1, 28)); // and month 1 is February, again ... // combine list1 and list2 into a new ArrayList named combined. //TODO // print combined list with size. HINT: use dateToFormattedString(...) // to print a GregorianCalendar's contents is a readable format //TODO // sort the combined list, print out the size of the combined list and its contents // HINT: use dateToFormattedString(...) here too //TODO // remove all dates where the year ends with '5' from the combined list // HINT: you must use Iterator or ListIterator // TODO // print out the size and contents of the modified combined list // HINT: use dateToFormattedString(...) here too //TODO } private static String dateToFormattedString(Calendar _date) { SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); return fmt.format(_date.getTime()); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started