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);
//Première utilisation du flux
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());
}
//réutilisation de flux--Échouer
try {
String collect_02 = stream.map(str -> "[" + str + "]").collect(Collectors.joining(";"));
System.out.println(collect_02);
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}
b;d;f;h;j;l;n;p;r;t;v;x;z
stream has already been operated upon or closed
――Pour traiter, compter, etc., tout ne devrait-il pas être diffusé en continu?
Recommended Posts