Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java
Sorting Method in java which use to sort any Object pass as parameter and return sorted Object
Posted 30-Apr-13 1:11am
Comments
Prasad Khandekar at 30-Apr-13 6:25am
   
Please have a look at the documentation for java.util.Arrays#sort(Object[] a). This utility method sorts the specified array of objects into ascending order, according to the natural ordering of its elements. All elements in the array must implement the Comparable interface.
 
Regards,
Maciej Los at 30-Apr-13 14:33pm
   
Can't you use generics to sort, compare "objects"?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You cannot 'sort any object'.
Strictly speaking you may just sort sets having an order criterion defined.
If you need sorting a collection (e.g. an array) of objects then the latter must provide a property (say 'key') such that using it you are be able establish the relative order of any two of them.
Supposing the objects provide such a key then you may use a well-known-good algorithm (like for instance Quick Sort[^] ) for sorting them.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100