Manning's Countdown to 2014
. Use discount code crdotd14 all month for 50% off every deal.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Programmer Certification (SCJP/OCPJP)
Ordered and Sorted
Joined: Nov 18, 2005
Jun 08, 2006 03:36:00
Can somebody explain howz order is defined? How to find which collection is ordered or unordered/sorted or unsorted?
Joined: Jul 11, 2003
Jun 08, 2006 04:29:00
Ordering & Sorting are 2 distinct names to same concept . Java has the concept of Natural Ordering means objects like Strings are self ordered in
Hence collections that contain
as key or string as objects are by default sorted .
Collections like List,Set ,Map need sorting . There are variants to these also like
,Hashtables need sorting...
If you want your objects to be sorted you have to implement a Comparator interface for that . It has a method compareTo(Object 1 , Object2) that sorts 2 objects while adding them in Collections.
There is also a utility method sort(Collection collection) on Collections class that sorts the collection .
Joined: Sep 14, 1999
Jun 08, 2006 07:59:00
Note that something that is ordered may not be sorted. Ordering means that the order of access is defined, e.g. I get stuff back in the order that I put it in. It may not however be sorted in any way.
SCWCD: Online Course, 50,000+ words and 200+ questions
subject: Ordered and Sorted
Is both Vector and Hashtable maintains object references in the order they were added?
ordered and sorted
Difference between sorted and ordered?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013