I have a list of Class Object in NamAryVar
I need check if String is equals to any NamVar of NamCls in the list.
I am doing this in two ways and I get the desired result.
But
I want to know which is faster, more efficient and uses less ressources in these two methods.
|*| Using for loop :
boolean FndResVab = false;
for(NamCls NamObjIdxVar : NamAryVar)
{
if(NamObjIdxVar.NamVar.equals("SomString"))
{
FndDupVab = true;
break;
}
}
|O| Using List Filter :
Boolean FndResVab = NamAryVar.stream()
.filter(IdxVar -> IdxVar.NamVar.equals("SomString"))
.count() == 1;
if(FndResVab)
{
// TskTdo :=> When Found
}
else
{
// TskTdo :=> When Not Found
}