mardi 18 octobre 2016

Replace multiple if-else that check if a substring is present or not

I want to know if there is any way i could optimize this code.

String[] array;
for(String s:array){
   if(s.contains("one"))
       //call first function
   else if(s.contains("two"))
      //call second function
   ...and so on
}

The string is basically lines I am reading from a file.So there can be many number of lines.And I have to look for specific keywords in those lines and call the corresponding function.

Aucun commentaire:

Enregistrer un commentaire