How optimized are Java 8 stream filters over collection methods?

Viewed 214

For example I have a comma separated string:

String multiWordString= "... , ... , ... ";

And I want to check whether another string str is present in the csv string. Then I can do following 2 things:

1.

boolean contains = Arrays.asList(multiWordString.split(",")).contains(str);

2.

boolean contains = Arrays.asList(multiWordString.split(",")).stream().filter(e -> e.equals(str)).findFirst();

EDIT: The sample string happens to use comma as a delimiter. I should have used the better name for sample string to avoid confusion. I updated the name. In this question I am trying to find the performance difference between using Java 8 streams and loops/collection methods.

3 Answers
Related