0
0

More than 1 year has passed since last update.

stream peek()

Posted at

peekはimediate processの途中で値を出力したりするときに使う
値を変更はしない
stream lineはeach elementについてfilter,peek,map,forEachされるイメージ

public class Outer {
    public static void main(String[] args) {
        List<String> l = List.of(
                "sato-a",
                "sato-b",
                "sato-c1",
                "sato-d1"
        );
        Stream<String> s = l.stream();
        s.filter(x -> x.length() == 6).peek(System.out::println).map(x -> x.toUpperCase()).forEach(System.out::println);
    }
}
sato-a
SATO-A
sato-b
SATO-B
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0