This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have say 25 if-else if conditions.So,should i have only 25 if-else if conditions.
Is there any better/effective way of checking it?
The disadvantage i see here is, if the condition satisfies only at 25th condition, it needs to check unnecessarily for 24 conditions.
PS : if-else if check i mean here can be anything (From String literal to an Object).
Is that what you were looking for? Maybe a while statement?
EDIT : The poster below has a better solution. Java 7 comes out July 28, 2011 FYI
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
Another solution might be to use a Map. I don't know exactly what expressions you have in your if-statements, so I can't tell you if this will work for your situation. But suppose that your chain of if-statements looks something like this: