Need to find out more optimized ways to code in Java.
Here is a very simple sample code
int index1 = line.indexOf(" ", word1.length() + 1);
if (!line.isEmpty() && index1 != -1) {
line = line.substring(word1.length(), index1).trim().toLowerCase();
}
or
if(!line.isEmpty() && line.indexOf(" ",word1.length()+1) != -1){
line = line.substring(word1.length(), index1).trim().toLowerCase();
}
What I noticed is the most of the times you have to decide between better code readability or perhaps more optimized code. Which one is better approach?
In all cases where performance increases are marginal or not completely justified, aim for