GeeCON Prague 2014*
The moose likes I/O and Streams and the fly likes Problems searching through a list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Problems searching through a list" Watch "Problems searching through a list" New topic
Author

Problems searching through a list

rosin tuck
Greenhorn

Joined: Jan 26, 2006
Posts: 5
Hey i have written a method to take two lists of strings as input, merge these two lists together, then go through each list individually and if it contains a word in the merge list, to return 1 otherwise return 0. However currently this only checks if the "exact" same string is in the list, as in it is case sensitive, i need it to be case insensitive for what i am trying to do


The return statement here is redundant i am just returning an int to test the method. Does anybody know how i can perform the same test while ignoring case? I would appreciate any help
Thanks
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I think you said the problem is that you want to ignore case so "hello" matches "Hello" in your search?

You could put everything into the list in lower case and do contains(word.toLowerCase())

You could make your own class instead of Strings ... something that holds a String and has an equals() method that ignores case.

Either of those sound useful?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
GeeCON Prague 2014
 
subject: Problems searching through a list