Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Sort Objects

Reply
Thread Tools

Sort Objects

 
 
Chris G
Guest
Posts: n/a
 
      04-13-2004
I have an array of Record[] objects that I want to sort. Each Record object
contains an int getPoints() method and I want to sort an array of these
records into descending points order.

Would I be correct in saying I implement the Comparable interface in my
Record class? If so what exactly do I include in the overridden compareTo
method? What integer value do I return? Also, how do I use the compareTo
method externally to do the sort?

Thanks in advance.


 
Reply With Quote
 
 
 
 
Christophe Vanfleteren
Guest
Posts: n/a
 
      04-13-2004
Chris G wrote:

> I have an array of Record[] objects that I want to sort. Each Record
> object contains an int getPoints() method and I want to sort an array of
> these records into descending points order.
>
> Would I be correct in saying I implement the Comparable interface in my
> Record class? If so what exactly do I include in the overridden compareTo
> method? What integer value do I return? Also, how do I use the compareTo
> method externally to do the sort?
>
> Thanks in advance.


Read the API docs and it should become clear:

http://java.sun.com/j2se/1.4.2/docs/...omparable.html
http://java.sun.com/j2se/1.4.2/docs/...omparator.html
http://java.sun.com/j2se/1.4.2/docs/...il/Arrays.html

--
Kind regards,
Christophe Vanfleteren
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      04-13-2004
On Tue, 13 Apr 2004 12:01:49 +0100, "Chris G" <>
wrote or quoted :

>Would I be correct in saying I implement the Comparable interface in my
>Record class? If so what exactly do I include in the overridden compareTo
>method? What integer value do I return? Also, how do I use the compareTo
>method externally to do the sort?


See http://mindprod.com/jgloss/comparable.html
http://mindprod.com/jgloss/comparator.html

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using s.sort([cmp[, key[, reverse]]]) to sort a list of objects based on a attribute cjt22@bath.ac.uk Python 7 09-10-2007 11:10 AM
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
Re: When will Thunderbird support sort in place (in context sort)? Ron Natalie Firefox 0 02-02-2006 04:38 AM
xsl:sort lang="es" modern vs. tradidional Spanish sort order nobody XML 0 06-01-2004 06:25 AM
Ado sort error-Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. Navin ASP General 1 09-09-2003 07:16 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57