• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to define comparator myself?

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you can create a class definition which implements the Comparator interface.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic