Click here to Skip to main content
13,055,408 members (52,065 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Sorting Method in java which use to sort any Object pass as parameter and return sorted Object
Posted 30-Apr-13 0:11am
Prasad Khandekar 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.

Maciej Los 30-Apr-13 14:33pm
Can't you use generics to sort, compare "objects"?

1 solution

Rate this: bad
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2017
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