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

Corey_819
Corey_819 used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

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

Author

Commented:
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.

Commented:
So you want to check if GD for example is in the list?
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Author

Commented:
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.
Commented:
You are maing sense - I am just veryfying that you are using a single value only:)

You will need to go through all of the elements until you find the proper one anyway unless you make some indexing or something like this... but internally it would work the same way. I would put all the possible values in an array/Vector/whatever linear structure (or even tree one), sort them on the day and then try something like a binary search. This will be the fastest I guess.

Otherwise - even on not ordered - a simple array and checking each element against the value that is checked (this done in a cycle) will do the trick...
Top Expert 2016

Commented:
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

Commented:
have you used case in java, its quite simple to do the task you need if you use the case statement.

Author

Commented:
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.
Top Expert 2016
Commented:

Author

Commented:
Thanks guys . :)
Top Expert 2016

Commented:
:-)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial