This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Ordering and Sorting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Ordering and Sorting" Watch "Ordering and Sorting" New topic
Author

Ordering and Sorting

Sunny Jain
Ranch Hand

Joined: Jul 23, 2007
Posts: 433

Can someone please explain me the difference between sorting and Ordering?
Both seems to be same and there is some difference..!! please explain with a real life example and relate it with Java..!!

Thanks in advance..!!!


Thanks and Regards,
SCJP 1.5 (90%), SCWCD 1.5 (85%), The Jovial Java, java.util.concurrent tutorial
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3165
    
  10
Originally posted by Sunny Jain:
Both seems to be same and there is some difference..!!


What makes you think there is a difference ?
In general they are the same thing, but I guess it's possible, in certain contexts, that there might be subtle differences.
If you have been told, or have read, that there is a difference, then we would need to know the context in order to answer your question.


Joanne
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18103
    
  39

In usage, "sorting" is a verb (or at least, I have only seen it used as a verb). As for "ordering", it is a noun (although, I do remember seeing it used as a verb once).

In the context of english usage, maybe you concluded that they are different because they are used differently?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
"Order" is overloaded in English...

I ordered some coffee, but my order came later than some later arrivals' orders. Ordering the disorderly orderly to my table, I told him that it was out-of-order for them to reorder the orders like that, and in order for me to reorder at their establishment again, an apology would be in order.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Sunny Jain
Ranch Hand

Joined: Jul 23, 2007
Posts: 433

Hi,

Well I got a good answer from one of my friend while chatting...he reminded me the 31st Dec, night:

We both were in the queue for entry in MOS (Ministry of Sound), So here we got some kind of Ordering..!! who so ever was coming..was joining us in the queue..now suppose if that time they would had announced please arrange yourself in the alphabetically Order ..then we will call it Sorting..So Sorting seems to be somewhat refined form of Ordering in Java context..!!!

But again it put one question in my mind..the Ordering was also time base sorting..???
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3165
    
  10
Originally posted by Sunny Jain:
now suppose if that time they would had announced please arrange yourself in the alphabetically Order ..then we will call it Sorting


No - you'd call that arranging
[ January 23, 2008: Message edited by: Joanne Neal ]
Milton Ochoa
Ranch Hand

Joined: Oct 23, 2007
Posts: 336

Hi Sunny

Recently (yesterday exactly) i was studing about Collections on the book Kathy Sierra, where explain before deep in the specfic collection (List, Set, Map), what mean Sorted, Unsorted, Ordered and UnOrdered.

If I am no wrong (i hope not) i will tell you what i undertood.

1. Order, think on a sequence, for example. 1, 2, 3,

2. Sort, mean reorganizete that order or no order in one specific "criterio" <- sorry for the spanish word.

for example.

-You have a NoteBook, where star to write from the begining to the end.

-When you want to read the notebook, star from the beginig too. (HERE IS THE ORDER).

-but, mas adelante (sorry again) you noted that the order when you wrote the notebook is no appropiate and you decide to SORT by some "criterio" maybe for "Color of ink when you was writing" I dont know (HERE IS SORTED)

Onother example but of UNSORTED and UNORDER.

-The pants pocket, when you save the coins maybe you dont think so much and just insert coins to you pocket.

-And when you retrieve this coins from the pocket, neighter have a order, just go out randomly.

Another Thing. Sorted is one kind of Order.

...
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I agree with Sunny's friend, and with Milton. Ordering and sorting (or ordered and sorted) are not the same thing. An ArrayList is ordered, which means that items in the List have a specific position which does not change unless someone specifically changes it. Most commonly, items are ordered in the order they were added to the list, and they stay in that order unless they are moved. However an ArrayList is not necessarily sorted. Sorting means you put items into a specific order which depends on some property or properties of the items. E.g. you can sort a list into alphabetical order (for one or more fields), or numeric order (for one or more fields) or some other order. You can't sort a list into insertion order unless "time of insertion" is one of the fields in the object.

An ArrayList is always ordered, but not necessarily sorted - unless you call Collections.sort().

A TreeSet is always sorted, and therefore always ordered as well - unless you change a value after it's been inserted, in which case you've broken the TreeSet, and you're an evil person who should be shot.

A HashSet is neither sorted nor ordered - or rather, it's sorted by the remainder of the hashcode, and the remainder can change depending on the capacity, so it's not advisable for anyone to pay attention to the order of a HashSet, and instead we consider it to be unsorted and unordered.
[ January 23, 2008: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
Sunny Jain
Ranch Hand

Joined: Jul 23, 2007
Posts: 433

So Overall we can say that:
/*****************************************************************************************/
Every Sorted sequence is Ordered, But Every Ordered sequence is not necessarily sorted.
/*****************************************************************************************/
Mark Newton
Ranch Hand

Joined: Jan 31, 2006
Posts: 129
Every Sorted sequence is Ordered, But Every Ordered sequence is not necessarily sorted.


I think I would say, "...has not necessarily been sorted".

Subtle difference, but I guess (on a purely semantic level), I would say that sorting is something that is done, ordering is something that just happens, either as a result of sorting (once you've sorted some things, they are in some order), or as a co-incidence (when people are standing in a queue, they, co-incidentally, are in chronological order).

Thinking about it, in English, things can be ordered, but I wouldn't say that I was 'ordering' something (in this sense, anyway), I'd always say that I was 'sorting', or 'putting in order'.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ordering and Sorting
 
Similar Threads
Comparable, Comparator
Comparators, comparble
Sort Directory paths, sort of.
Suggestion about data structure to be used for piecewise defined functions.
difference between sorting and ordering