Java 8: Converting An Array To A Stream

The Java 8 Arrays class allows a convenient conversion between an array and a Stream:

import java.util.Arrays;
import static;
import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test;

public class ArraysToStreamTest {

    public void arraysToStream() {
        String languages[] = {"java", "javascript"};
        Stream<String> stream =;

        long count = stream.filter(l -> l.endsWith("va")).count();
        assertThat(count, is(1l));


See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home:


What's the difference with Stream.of(...) ?

Posted by AlexThep on January 01, 2017 at 12:31 PM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments