Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to define comparator myself?

 
lijun wang
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can create a class definition which implements the Comparator interface.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the source code for CASE_INSENSITIVE_ORDER, as an example:


Does anyone know why it uses both toUpperCase and toLowerCase?
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic