This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to define comparator myself?" Watch "how to define comparator myself?" New topic
Author

how to define comparator myself?

lijun wang
Greenhorn

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

Thanks!!!
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?

Yuriy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to define comparator myself?
 
Similar Threads
Constraints
A Question about The Life Cycle of a Stateless Session Bean
How map the first servlet to second servlet
Kathy's latest horse video :)
Using a multidimensional array