improve if else statement for multiple condition

Posted by kitokid on Programmers See other posts from Programmers or by kitokid
Published on 2012-06-04T08:55:48Z Indexed on 2012/06/04 10:50 UTC
Read the original article Hit count: 191

Filed under:
|
|

My superior said the following is bad code. But he didn't mention anything how to improve it.

What might be the alternative elegant way of coding below statements, without using if else?

if(name.equalsIgnoreCase("AAA")){
//do something
}else if(name.equalsIgnoreCase("BBB")){
//do something
}else if(name.equalsIgnoreCase("CCC")){
//do something
}else if(name.equalsIgnoreCase("DDD")){
//do something
}else if(name.equalsIgnoreCase("EEE")){
//do something
}else{
//do something
}

Edited: I am using Java 6.

© Programmers or respective owner

Related posts about java

Related posts about coding-style