• 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

Make list element case-insensitive

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my java application i need to compare two list's element whether it is similar or not.

In short suppose i have two list declared like shown below


If i write a condition for equality it fails as some of list's element is in different case like


It will display result "Not equal"

So please tell me how i can make the list element case-insensitive in java language only.

Thank and regard
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try looking in the API for String where you will probably find something useful very quickly.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Try looking in the API for String where you will probably find something useful very quickly.



I assume you are referring to String.equalsIgnoreCase(). That was my first thought as well until I re-read the OP. a and a1 are Arraylists containing Strings, not Strings. Sorry if I'm wrong about your assumption, but I couldn't see anything in the String API that would help here.

My second thought was to check the Collections class to see if it had an equals or compare method that took a Comparator as a parameter, but I couldn't see anything. Maybe satya could write such a method.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a sort that takes a comparator.
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I meant both equalsIgnoreCase and the built-in Comparator in the String class, Joanne; you need that Comparator, otherwise it will sort "ONE" "THREE" "two". As you say, you would have to write your own method using it equalsIgnoreCase.

And yes, just like you, I thought it meant comparing the Strings. Sorry.
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote: . . . "ONE" "THREE" "two". . .

Or "ONE" "TWO" "three" depending on the inputs. Please google for ASCIIbetical order, Satya.
 
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic