Hi
I need a alternative approach for the following code segment.
I have a task where a particular string has to be checked if it is one among the following values
(byte,boolean,string,char,int,float,doublee);
I have used if else logic to check that value and the code is as follows
if(!names.equalsIgnoreCase("byte"){
if(!names.equalsIgnoreCase("boolean"){
if(!names.equalsIgnoreCase("char"){
if(!names.equalsIgnoreCase("int"){
if(!names.equalsIgnoreCase("double"){
if(!names.equalsIgnoreCase("float"){
if(!names.equalsIgnoreCase("short"){
if(!names.equalsIgnoreCase("long"){
return true;
}
}
}
}
}
}
}
}
Can any other alternative way can be used to code this , so that the code becomes simpler .
Thanks in advance
shylaja
I need a alternative approach for the following code segment.
I have a task where a particular string has to be checked if it is one among the following values
(byte,boolean,string,char,int,float,doublee);
I have used if else logic to check that value and the code is as follows
if(!names.equalsIgnoreCase("byte"){
if(!names.equalsIgnoreCase("boolean"){
if(!names.equalsIgnoreCase("char"){
if(!names.equalsIgnoreCase("int"){
if(!names.equalsIgnoreCase("double"){
if(!names.equalsIgnoreCase("float"){
if(!names.equalsIgnoreCase("short"){
if(!names.equalsIgnoreCase("long"){
return true;
}
}
}
}
}
}
}
}
Can any other alternative way can be used to code this , so that the code becomes simpler .
Thanks in advance
shylaja