• 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

Ordered and Sorted

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone explain how come a SortedSet is sorted and not ordered? It seems counter inutitive that something should be sorted and not ordered to me (as sorted means that elements are comparatively put in order does it not? If the elements are sorted how can this be helpful if the set is not ordered? Also which Collections are ordered and which are sorted?
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to the Sun Java Tutorial:
The SortedSet Interface
A SortedSetis a Setthat maintains its elements in ascending order, sorted according to the elements' natural order, or according to a
Comparator provided at SortedSet creation time. (Natural order and Comparators are discussed in the previous section, on Object Ordering.) In
addition to the normal Set operations, the Set interface provides operations for:
Range-view: Performs arbitrary range operations on the sorted set.
Endpoints: Returns the first or last element in the sorted set.
Comparator access: Returns the Comparator used to sort the set (if any).
The SortedSet interface is shown below:
public interface SortedSet extends Set {
// Range-view
SortedSet subSet(Object fromElement, Object toElement);
SortedSet headSet(Object toElement);
SortedSet tailSet(Object fromElement);
// Endpoints
Object first();
Object last();
// Comparator access
Comparator comparator();
}
http://java.sun.com/docs/books/tutorial/collections/interfaces/sorted-set.html
 
Enthuware Software Support
Posts: 4810
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can say Sorting is a special kind of Ordering. SortedSet keeps the elements ordered accoring to their ascending natural order or the order governed by the comparator as explanied above by Cindy.
A List on the other hand keeps the elements ordered. ie. in the sequence they were added. You can be sure of the sequence of elements in a list but you can't be sure what sequence the elements are stored in a Set so it is not ordered.
HTH,
Paul.

------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus
 
reply
    Bookmark Topic Watch Topic
  • New Topic