这是代码的和平,我希望它能够提高效率 我看到很多 if else 语句,
谁能帮我简化一下并减少代码行数
if(mmPageCounter.equalsIgnoreCase("trueNotFull")){
if(whatPageNext.equalsIgnoreCase("first"))
accountListSize = 5;
else
accountListSize = acctIdList.size();
}else if(mmPageCounter.equalsIgnoreCase("true")){
if(whatPageNext.equalsIgnoreCase("first"))
accountListSize = 5;
else
accountListSize = 10;
}else if(mmPageCounter.equalsIgnoreCase("false")){
if(whatPageNext.equalsIgnoreCase("alwaysFirst"))
accountListSize = acctIdList.size();
}
在上面的代码中,基于 mmPageCounter 的值,我设置了 For 循环的索引要么是满容量,要么是实际值
满容量意味着,for循环只会迭代10个项目
ps:我已经让代码工作并且很好,但我只寻找微调
如果有人有任何微调技巧,请分享链接。
最佳答案
我会反过来写。 什么时候账户大小应该设置为10? 什么时候帐户大小应设置为 5?
if(shouldBeFive()){
accountListSize = 5;
} else if (shouldBeTen()){
accountListSize = 10;
} else{
accountListSize = acctIdList.size()
}
您还可以在 java7 中切换大小写。
关于java - if else 语句的代码清理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6121519/