mercredi 1 juillet 2015

Get field details inside list without large if else condition in Java

I have a List of objects. The list is quiet big. All the values are String. Currently I'm doing for each loop with if condition. But readability will not be good and it becomes lengthy. Following is the code snippet:

List<Fields> fieldList = <(device,value),(quantity,value),(position,value),(Note,value),(Model,value),(LotNumber,value)...>;    
for(Fields fl : fieldList)
{
 if(fl.name.equals("device"))
  doSomething();
else if(fl.name.equals("quantity"))
 doSomething();
//This goes on
}

Please suggest a better way. Note: Time is not a factor.

Aucun commentaire:

Enregistrer un commentaire