Answer Posted / nitesh
Right now two ways come to my mind.
First:
Create a TreeSet, add all the dates to it. They get
sorted by default since java.util.Date implements
comparable. Here is an example -->
Set<Date> sortedDates = new TreeSet<Date>();
sortedDates.add(new Date());
Calendar cal = Calendar.getInstance();
cal.set(2009, 2, 12);
sortedDates.add(cal.getTime());
Second:
We can use the compare method inside Date class
directly and write our own sorting implementation.
| Is This Answer Correct ? | 11 Yes | 5 No |
Post New Answer View All Answers
What is the use of static methods?
What comes to mind when someone mentions a shallow copy in java?
What differences exist between iterator and listiterator?
Describe different states of a thread.
What is hash table in java?
What is the arraylist in java?
What is a blocking method in Java?
What are bind parameters?
How is final different from finally and finalize?
Give us a program to check for parenthesis matching using stack.
What is java abstraction with example?
Can I learn java without any programming experience?
What is the inheritance?
What is flush buffer?
What is methods and methodology?