How do I use != in java strings

My code has a validator which states that if "d" is entered display an error message. If "c", "s", or "v" are entered do the calculation. How can I construct gender.equalsIgonreCase to include all words and letters that are not "c", "s", or "v"?

Answers


You could use String.matches(String) which takes a regular expression to validate gender. Like

boolean isCSV = gender.matches("[CcSsVv]");
if (!isCSV) {
    // It isn't C, c, S, s, V or v
}

you can use "else" :

if(gender.equals("C")){
....
}
else if(gender.equals("S")){
....
}
else{
.....
}

or you can use !gender.equals("d"):

if(!gender.equals("d")){
.....
}

Need Your Help

Android Applications Linking Activity

android imagebutton

I have two different activities in my android applications. The first(MainActivity) has ImageButton through which onClick it's getting navigate two second activity(Numbers). This is my code of

IE7 won't display images in dynamically generated iFrame

image iframe printing internet-explorer-7

In order to aid with printing, I'm dynamically generating an iFrame and then populating it with some content. This works on IE6, IE8, Chrome and Firefox on both PC and Mac. The problem is for some ...