0

We can create stream from List of string like this

    List<String> list = Arrays.asList("somestring");
    Stream<String> stream = list.stream();

But how to create stream directly from string.

String x = "somestring";
0

2 Answers 2

9

You can use Stream.of which returns a sequential Stream containing a single element.

Stream<String> stream = Stream.of(x);
Sign up to request clarification or add additional context in comments.

Comments

3

You can try Stream.of("somestring")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.