public class StreamTest {
public static void main(String[] args) {
//Generate a Stream of type String
Stream<String> stringStream = Stream.of("1", "2", "3", "4", "5");
// Convert string type in stream to int type using map method
stringStream.map(
(String s) ->{
return Integer.parseInt(s);
});
stringStream.forEach(i -> System.out.println(i));
}
}
As shown in the figure, the code runs with an error:
The stream has been used or closed
This is a feature of streams: a stream can only be used once!
Read More:
- Stream to MemoryStream to solve Stream.Length error report This stream does not support search operations
- Git push error: error: RPC failed; curl 92 HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)
- [Solved] iperf Analyze Error: unable to create a new stream: Invalid argument
- How to Solve Spring Cloud Error context has been closed already
- DB2 detects a syntax error in the DRDA data stream: 0x3 ERRORCODE= -4499, SQLSTATE=58009
- XML read process error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1] Message: Content not allowed in preamble
- [Solved] Git error: inflate: data stream error (invalid block type) error: corrupt loose object
- [Solved] Websocket Error: WebSocket is already in CLOSING or CLOSED state
- Android Error: Consumer closed input channel or an error occurred. events=0x9
- Centos7 hive started to report an error. There is no route to the host. The firewall has been closed
- Git: “error: RPC failed; curl 18 transfer closed with outstanding read data remaining”
- Docker: How to Enter the Closed Container and View the Logging
- Spark-shell startup error: Yarn application has already ended! It might have been killed or unable to launch application master
- [Solved] HBase shell command Error: ERROR: connection closed
- [Solved] An unexpected error has occurred. Conda has prepared the above report.
- Docker Error response from daemon: Get https://registry-1.docker.io/v2/: x509: certificate has expired or is not yet valid
- Conda create New environment Error: An unexpected error has occurred. Conda has prepared the above report.
- Android: Can’t create handler inside thread that has not called Looper.prepare() [Solved]
- OpenCV(-206:Bad flag (parameter or structure field)) Unrecognized or unsupported array type [How to Solve]
- [Solved] Error: The superclass, ‘Animal‘, has no unnamed constructor that takes no arguments.