1. Member
Join Date
Sep 2011
Posts
9
Rep Power
0

about conditonal if else and switch case

hello sir,
Is there any way to replace if-else and switch statement to any other logic.my question is that if we change if-else to some another thing ..the how it will easier to me ...

2. Re: about conditonal if else and switch case

A sequence of if-else if-else if ... else statements can be simulated by a Map<Condition, Runnable> where the Condition object represents the conditon in an if (...) clause; a switch statement is more difficult to handle with a Map because of the 'fall through' behaviour.

kind regards,

Jos

3. Member
Join Date
Feb 2011
Posts
4
Rep Power
0

Re: about conditonal if else and switch case

It depends on the conditions, if they are numbers you can manipulate them using logical operators, for example:

double x = ...
if(x >= 0) System.out.println("x is greater than or equal zero!");
else System.out.println("x is negative number!");
you can do this without if statement:

double x = ...
String[] arr = {"x is greater than or equal zero!", "x is negative number!"};
System.out.println(arr[(int) Math.ceil(x) >>> 31]);
Last edited by FOUAD-SPIDER; 09-22-2011 at 10:49 AM.

4. Member
Join Date
Sep 2011
Posts
9
Rep Power
0

Re: about conditonal if else and switch case

hey jos'
can u pls show it to by some example.

thanks alot

5. Member
Join Date
Mar 2010
Posts
7
Rep Power
0

Re: about conditonal if else and switch case

You can check java api by typing java api 1.6 in google...

that has complete detail about java. and just go for java.util package there. You'll c Map and other alternatives of if-else.

Thanx
Anoop

6. Member
Join Date
Sep 2011
Posts
9
Rep Power
0

Re: about conditonal if else and switch case

thanks anoop,
but i need also to know that how map is usefull to me over on if-else. for example if i have several if-else in my code and i replace them all by map..so,how they are useful to me.

7. Member
Join Date
Sep 2011
Posts
9
Rep Power
0

Re: about conditonal if else and switch case

dear jos,

what do u meant by runnable there..can u show it by an example ..its very important for me ...please give answer as soon as possible

thanks

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•