Results 1 to 4 of 4

Thread: Problem with .equalsIgnoreCase

  1. #1

    Thread Starter
    Hyperactive Member Animelion's Avatar
    Join Date
    Jan 2001
    Location
    Jacksonville NC
    Posts
    283

    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
    ~ Animelion

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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.

  3. #3

    Thread Starter
    Hyperactive Member Animelion's Avatar
    Join Date
    Jan 2001
    Location
    Jacksonville NC
    Posts
    283

    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

  4. #4
    Lively Member
    Join Date
    Oct 2005
    Posts
    74

    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
  •  



Click Here to Expand Forum to Full Width