我有一个对象数组。对象中有一个 getCountry()。当 getCountry() 等于说“XXX”时,我想设置一个标志。
据了解,我正在做,
boolean isXXX=false;
if(custAcctArray != null)
{
for(int index=0;index<custAcctArray.length;index++)
{
if(custAcctArray[i].getCountry().equalsIgnoreCase("XXX"))
{
isXXX=true;
}
}
}
if(isXXX)
{
Do something about it....
}
当我假设数组充满了大约 100 个或奇怪的对象时,我不知何故不喜欢这种逻辑。有人可以通过其他方式以有效的方式实现最终输出吗? 我想要什么:当getCountry() == " XXX "时设置一个标志