Avatar of Corey_819
Corey_819
 asked on

Looking through a long list of values w/o IF ORs

Hello and how is it? I am looking for just the quickest way to do a big list of conditions. I have to do something in my code based on if a field could have a set of 50 or so values. I am not sure, but I do not not think a bunch of IF || ..... statements is the quickest way to process my code. What would be the quickest way to look through this long list of values for a single match? thanks
Java

Avatar of undefined
Last Comment
CEHJ

8/22/2022 - Mon
CEHJ

Give us an example of a couple of things that you might do
Corey_819

ASKER
Sure thing:

PA,PF,PC,PQ,PP,PV,PR,PB,PO,PG,PD
BA,BD,BC,BE,BH,BO,BN,BP, DS,GR,GC,GD,GM,GP,GN,GO,GP,GT,GS ,GA,OP,HD,RE,ED,CO,DS

Here would be a lilst to find a match of one of those values.
Venabili

So you want to check if GD for example is in the list?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Corey_819

ASKER
Well either one could be being passed in the string, but yeah GD would be an example. Bud could be DS or PQ, or ....... I am sorry if I am not making sense.
SOLUTION
Venabili

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
CEHJ

I'm talking about what you would do *after* finding it. Finding it would be easy:

List<String> strings = .....
if (strings.contains("GD")) {
....
}

but that won't get rid of ifs
arkoak

have you used case in java, its quite simple to do the task you need if you use the case statement.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Corey_819

ASKER
Sorry good question CEHJ, If a value is found send string out of a pipe as one format, if not found then send string out as another format.
ASKER CERTIFIED SOLUTION
CEHJ

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Corey_819

ASKER
Thanks guys . :)
CEHJ

:-)
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes