Java Stream cannot be reused.

Could not be reused.

import java.util.stream.*;

public class StreamTest {

	public static void main(String[] args) {

		// a-Streaming z
		Stream<String> stream = Stream.iterate('a', c -> ++c).map(Object::toString).limit('z' - 'a' + 1);

		//first use of stream
		try {
			String collect_01 = stream.filter(str -> {
				byte[] b = str.getBytes();
				return (b[0] % 2 == 0);
			}).collect(Collectors.joining(";"));
			System.out.println(collect_01);
		} catch (Exception e) {
			System.err.println(e.getMessage());
		}

		//stream reuse--Fail
		try {
			String collect_02 = stream.map(str -> "[" + str + "]").collect(Collectors.joining(";"));
			System.out.println(collect_02);
		} catch (Exception e) {
			System.err.println(e.getMessage());
		}

	}

}

result

--I got the error [stream has already been operated upon or closed].

b;d;f;h;j;l;n;p;r;t;v;x;z
stream has already been operated upon or closed

――In order to process, count, and so on, shouldn't everything be stream?

Recommended Posts

Java Stream cannot be reused.
Java cannot be installed on Ubuntu 13.04
[JAVA] Stream type
Try Java 8 Stream
Java Stream API
Studying Java 8 (Stream)
Java Stream termination
[Java] Stream processing
Java 9 Optional :: stream
[Java] Scenes that cannot be reassigned (substantially final)
[Solution] Java cannot be installed on Windows 10 + ATOK 2017
Why Java String typeclass comparison (==) cannot be used
Kotlin's reified function cannot be called from java.
[Java] Stream Collectors notes
[Java] Stream API-Stream generation
[Java] Stream API / map
Java8 Stream API practice
Java8 Stream reduction operation
Java8 Stream Rough Summary
Tomcat cannot be started due to java version change
Stream processing of Java 8 can be omitted so far!
Only the top level Stream can be parallelized with Java Stream.
[Java11] Stream Summary -Advantages of Stream-
Because getSupportLoaderManager cannot be used
Java Stream API cheat sheet
Java Stream API in 5 minutes
Cannot find javax.annotation.Generated in Java 11
Java8 stream, lambda expression summary
[Java] Stream API --Stream termination processing
[Java] Stream API --Stream intermediate processing
[Java] Introduction to Stream API
Use Redis Stream in Java
[Java11] Stream Usage Summary -Basics-
Java application for beginners: stream
[Java] Stream API intermediate operation
Text file placed in resources in Java cannot be read when jarted
Note that system properties including JAXBContext cannot be used in Java11
[Java 8] Duplicate deletion (& duplicate check) with Stream
The org.junit.jupiter.api package cannot be found.
[Java] Stream (filter, map, forEach, reduce)
CentOS7 VirtualBOX yum cannot be used
[java8] To understand the Stream API
About Lambda, Stream, LocalDate of Java8
[Introduction to Java] About Stream API
Spring-security error message cannot be changed
[Java] December 28, 2020 will be formatted as December 28, 2021?
[Java] Element existence check with Stream
[PHP] Solved "mb_strpos cannot be used"
Java to be involved from today
I tried using Java8 Stream API
Measures when model cannot be created
Basic processing flow of java Stream
[Rails 6] MySQL 2 cannot be bundle install
Java 8 ~ Stream API ~ to start now
Java array / list / stream mutual conversion list
Java8 list conversion with Stream map
Do you use Stream in Java?
Android Studio JRE cannot be changed
Java code that cannot be used from Kotlin (for in-house study sessions)
[Java] Variables declared inside the `for statement` cannot be used outside the` for statement block`