Besides combining your 3 ifs into one:
if(statement1 && statement2 && statement3)
There are other ideas that come to mind:
If the value of importsPreparedStatement should be true only once, you can break; after setting it to true . Therefore, if it makes no sense to search more after you set the field to true , use break; .
From a design point of view, you can combine an if into a method, for example doesImportPreparedStatement or isImportingPreparedStatement , or possibly containsImportPreparedStatement .
I see one more thing. You repeat your packageDefinition , but you check the three elements one after another. I assume they are grouped in groups of 3 so that you can do something like this:
for (int j = 0; j < packageDefinition.size() - 2; j += 3)
From a design point of view, if I were you, I would put these 3 elements in my own class, in which case you can simplify things, and it will look like this:
for(DefinitionElement e : packageDefinitions) { if(e.doesImportPreparedStatement()) { importsPreparedStatement = true; break; } }
In the latter case, the DefinitionElement type will contain three elements that you group together in your array, and a method that can determine whether it contains the import of ready-made statements or not. I think this form is more readable and easy to maintain. From my experience, indexing is not fun, and you have to understand the context in order to know what j + 2 means.
If you do not want (or cannot) move them to your class, you can at least give a name to the index j + 2 and j + 1 , in order to find out later what they mean.