File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes performace to sort large Date objects ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "performace to sort large Date objects ?" Watch "performace to sort large Date objects ?" New topic
Author

performace to sort large Date objects ?

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
If I have a large java.util.Date objects with OR without duplication, which way has best performance to sort ?

Thank.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

I will assume you mean a large number of Date objects (because all java.util.Date Objects should be roughly the same size).

I suspect the best way to do your sorting will be to use Collections.sort(List<Date>). You would have to prove that that method was too slow or doesn't sort the way you want before you look for other options.


Steve
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

But another option would be to use a collection that orders objects as they are inserted. Since you allow doubles of the same Date the best bet would be a PriorityQueue<Date>. This pushes the cost of sorting forward to the addition of objects, but means there is little/no cost to reading the Dates in order.

When you use an un-order collection, or one that uses insertion order like List, you then use Collections.sort(). It means there is little cost to adding new objects, but before you read them you need to sort which can cost you time.

So if you need a continuous adds/reads you might find it easier and more efficient to use a PriorityQueue. If you collect a large number of Dates then after collecting them need to read them in order then Collections.sort might be better.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

And Relevant Links:
Collections
PriorityQueue
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: performace to sort large Date objects ?