0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Streamの生成処理

Last updated at Posted at 2019-11-17

Java8から導入されたStreamAPI
Collectionの操作に便利な処理がたくさんある
(いまさらになるが)メモ的な感じで列挙していこうと思う。

StreamAPIとは
Stream自体はListやMapなどのCollection要素ではなく、配列やリストなどの要素に対して生成処理、中間処理、終端処理を加えて新しい要素に置き換えるためのパイプラインのようなものという認識

Stream#of

Stream<String> stream = Stream.of("a","b","c");

Collection#stream

Listからの生成

List<String> list = Arrays.asList("a","b","c");
Stream<String> stream = list.stream();

Mapからの生成

Map<String,String> map = new HashMap<>();
Stream<Entry<String,String>> stream = map.entrySet().stream();

Arrays#Stream

String[] array = {"a","b","c"};
Stream<String> stream = Arrays.stream(array);

BufferedReader#lines

BufferedReader reader = new BufferedReader(newInputStreamReader(System.in, directory));
Stream<String> reader.lines();   
0
0
2

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?