需要找到更优化的Java编码方法.
这是一个非常简单的示例代码
int index1 = line.indexOf(" ", word1.length() + 1);
if (!line.isEmpty() && index1 != -1) {
line = line.substring(word1.length(), index1).trim().toLowerCase();
}
Run Code Online (Sandbox Code Playgroud)
要么
if(!line.isEmpty() && line.indexOf(" ",word1.length()+1) != -1){
line = line.substring(word1.length(), index1).trim().toLowerCase();
}
Run Code Online (Sandbox Code Playgroud)
我注意到的是大多数时候你必须在更好的代码可读性或更优化的代码之间做出决定.哪一个更好的方法?
归档时间: |
|
查看次数: |
1084 次 |
最近记录: |