Problem with .equalsIgnoreCase
Is there an easy way to do this ?
if(_houseColor.equalsIgnoreCase( "White" || "Red" || "Blue" || "Yellow" || "Black" || "Green" ) ){
This is as far as I got, I don't want to say .equalsIgnoreCase for each possibility.
All help is appreciated ~Bryan J. Casler
Re: Problem with .equalsIgnoreCase
Not as such. You could compare against a regex, but that's a waste of speed IMO. You could also fill an array with the values and search through it. Or create a set. Something like this:
Code:
private static final Set<String> colourNames = new HashSet<String>(
Arrays.asList(new String[]{ "red", "green", "blue", ... }));
// ...
if(colourNames.contains(colour.toLowerCase())) {
}
Re: Problem with .equalsIgnoreCase
Thanks CornedBee,
I had thought about doing something similar to that, but hoped I was missing a simpler solution. If anyone else has an easier method please post. ~Bryan J. Casler
Re: Problem with .equalsIgnoreCase
The array is the best way.