Issue
If we have two simple lists where one have only one repeating value:
List<String> states = Arrays.asList("Excelent", "Excelent", "Excelent");
and the other one have one different value:
List<String> states = Arrays.asList("Excelent", "Excelent", "Good");
how can I check if list contains anything other than "Excelent" in this case?
It should looks something like:
private boolean check(List<String> states){
//Some condition where we can say if there is any item not equal to "Excelent"
}
Solution
There are many ways to solve it.
You can for example streaming it and filter for values different to Excelent
private boolean check(List<String> states){
return states.stream()
.filter(item -> !item.equals("Excelent"))
.count() > 0;
}
Answered By - Davide Lorenzo MARINO
Answer Checked By - Timothy Miller (JavaFixing Admin)