Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to check if string list contains anything other than some value?

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading