Compare a String to Multiple Strings in java
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...
40 Minutes
Discussion Span
myadav
Newbie Poster
8 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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.
jalpesh_007
Posting Whiz
328 posts since Sep 2010
Reputation Points: 4
Solved Threads: 36
Skill Endorsements: 3
Yeah ...Its working .....Great !!!!
Thank You soo muchh
myadav
Newbie Poster
8 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 5 Months Ago by
jalpesh_007