File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes how to define comparator myself? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to define comparator myself?" Watch "how to define comparator myself?" New topic

how to define comparator myself?

lijun wang

Joined: Jan 20, 2006
Posts: 28
can I define the comarator?
for example, how can I define first>second or first<second?, second)

Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Yes, you can create a class definition which implements the Comparator interface.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Here is the source code for CASE_INSENSITIVE_ORDER, as an example:

Does anyone know why it uses both toUpperCase and toLowerCase?

There is no emoticon for what I am feeling!
Yuriy Zilbergleyt
Ranch Hand

Joined: Dec 13, 2004
Posts: 429
Originally posted by Jeff Albertson:

Does anyone know why it uses both toUpperCase and toLowerCase?

Yeah, that does look mighty strange. I can't think of a case when (Character.toUpperCase(c1) != Character.toUpperCase(c2) && Character.toLowerCase(c1) == Character.toLowerCase(c2)) evaluates to true. Are they just being overparanoid?

I agree. Here's the link:
subject: how to define comparator myself?
It's not a secret anymore!