1.11M Members

Compare a String to Multiple Strings in java

 
0
 

Hi All

I am new to java. I am facing a problem
I want to compare a string to a set of strings,
For example there is variable string x, If the value String X matches to String A , String B, String C then run the particular code otherwise do not run anything and come out of the loop.

My Code is:

    if((!X.equals("IND"))&&(!X.equals("AJD"))&&(!X.equals("BE"))){
    if (X.equals("IND")) {

        try {
            System.out.println("Form Type dropdown contains Individual");
        } catch (AssertionError e) {
            e.printStackTrace();
        }
    }

    if (X.equals("ADJ")) {
        try {

            System.out.println("Form Type dropdown contains Adjuster");
        } catch (AssertionError e) {
            e.printStackTrace();
        }
    }

    if (X.equals("BE")) {

        try {

            System.out.println("Form Type dropdown contains BE");
        } catch (AssertionError e) {
            e.printStackTrace();
        }
    }
    }else{
        System.out.println("Drop Down value does not match Individual, BE, and Adjuster");
    }
}

But os not wroking as desired ....:(
Please help!!!
Thanks in Advance...

 
0
 

simple use if...elseif ladder to get output.
Like:

if(a.equals(b))
{
}
elseif(a.equals(c))
{
}
elseif(a.equals(d))
{
}
else
{
}

i think its work.

 
0
 

Yeah ...Its working .....Great !!!!
Thank You soo muchh

Question Answered as of 1 Year Ago by jalpesh_007
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article