Keep in mind Strings implement Comparable.  So if the lastName field of your 
PeopleBean is a String it makes the local sorting that much easier (no need to make 
changes to the PeopleBean).  You can just do the comparisons based on the lastName 
field (or any other field that implements Comparable).

-----Original Message-----
From: David Haynes [mailto:[EMAIL PROTECTED] 
Sent: Monday, March 10, 2003 12:59 PM
To: 'Struts Users Mailing List'
Subject: RE: Sort a collection in alphabetic order

Although I don't know anything about Soren's specific problem, I have
had times where the database is protected by a bean and the process of
having a new data access method on the bean is simply too complex to be
believed (i.e. you have about a gazillion review processes to go
through). In these cases, I have found it sometimes useful to take the
data as it comes and massage it locally.

-david-

-----Original Message-----
From: apachep2 [mailto:[EMAIL PROTECTED] 
Sent: March 10, 2003 3:54 PM
To: 'Struts Users Mailing List'
Subject: RE: Sort a collection in alphabetic order

Comparable is always a good idea. But I am curious to know why you are
unable to do a re-SELECT statement?

-----Original Message-----
From: David Haynes [mailto:[EMAIL PROTECTED] 
Sent: March 10, 2003 3:49 PM
To: 'Struts Users Mailing List'
Subject: RE: Sort a collection in alphabetic order

Since you are in a while(rs.next()) context, why not sort on insertion?
Just pop your results into a Vector (or other collection) in sort-order.
Depending upon the number of elements expected, you could speed the
insertion using a number of methods. If your lists are relatively small,
it may be efficient to just start at the beginning of the vector and
walk through it looking for the insertion point.

-david-

-----Original Message-----
From: Søren Blidorf [mailto:[EMAIL PROTECTED] 
Sent: March 10, 2003 1:25 PM
To: 'Struts Users Mailing List'
Subject: SV: Sort a collection in alphabetic order

It is not possible.

The select is in a while (rs.next()) {} depending on another value. (Not
easy to explain!!)

I am a ware of normal SQL order by

-----Oprindelig meddelelse-----
Fra: Dave Newton [mailto:[EMAIL PROTECTED] 
Sendt: 10. marts 2003 19:20
Til: Struts Users Mailing List
Emne: Re: Sort a collection in alphabetic order

On Mon, 2003-03-10 at 13:16, Søren Blidorf wrote:
> I need to sort my collection "people" in alphabetic order by lastname,
> firstname. Can anybody help me?

Most algorithm books will give you more information than you want on
sorting.

Why not just do it in the query and let the db do it?

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to