4
1

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 5 years have passed since last update.

入れ子になっているListにStreamAPIを使ってみた

Posted at

個人的なメモ

java8の勉強をちょっとしてみた。

Listが入れ子になっている場合、
StreamAPIをどうやって使えばいいか知りたかったのでコードを書いてみました。
まずは表示されたので、この使い方であっているのかな。

public class AppMain {
    public static void main(String[] args) {
        AppMain main = new AppMain();
        main.execute();
    }

    private void execute() {
        List<List<String>> list = getList();
        printout(list);
    }

    private void printout(List<List<String>> list) {
        list.stream().forEach(
                childList -> childList.stream().forEach(System.out::println));
    }

    private List<List<String>> getList() {
        List<List<String>> list = new ArrayList<>();
        list.add(Arrays.asList("aa11", "aa22"));
        list.add(Arrays.asList("bb11", "bb22"));
        list.add(Arrays.asList("cc11", "cc22"));
        return list;
    }
}
4
1
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
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?