|
-
Dec 12th, 2006, 01:30 AM
#1
Thread Starter
Hyperactive Member
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
-
Dec 12th, 2006, 05:02 AM
#2
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())) {
}
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 12th, 2006, 02:55 PM
#3
Thread Starter
Hyperactive Member
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
Last edited by Animelion; Dec 12th, 2006 at 02:55 PM.
Reason: Rewording of sentence
~ Animelion
-
Dec 13th, 2006, 03:37 PM
#4
Lively Member
Re: Problem with .equalsIgnoreCase
The array is the best way.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|