For my work I have to develop a small Java application that parses very large XML files (~300k lines) to select very specific data (using Pattern), so I'm trying to optimize it a little. I was wondering what was better between these 2 snippets :

if(boolean_condition && matcher.find(string))
{
...
}

OR

if(boolean_condition)
{
if(matcher.find(string))
{
...
}
}

More precisions :

These if statements are executed on each iteration inside a loop (~20k iterations)

The boolean_condition is a boolean calculated on each iteration using an external function

If the boolean is set to false, I don't need to test the regular expression for matches

Both ways are OK, and the second condition won't be tested if the first one is false.

Use the one that makes the code the more readable and understandable. For just two conditions, the first way is more logical and readable. It might not be the case anymore with 5 or 6 conditions linked with &&, || and !.