How to find if all elements of list are in a set in Java 8?

Tanvi Jaywant :

While it is easy to do it in a for loop, is there a way in Java-8 to find if all elements in list L are present in Set s ?

Ousmane D. :

You can use allMatch:

boolean result = l.stream().allMatch(s::contains);

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=442879&siteId=1