Help us understand the problem. What is going on with this article?

業務で役立ったJava No.2 Optionalリストにfilterをかけ、一つめの値を取得

More than 1 year has passed since last update.

前回に続き、null関係
業務で役立ったJava No.2

文字列のリストをfilterにかけて最初の一つを取り出す方法

Optional<String> firstStr = selectedList.stream()
                .filter(p -> p=="fuga")
                .findFirst();

外部APIから戻り値に1or0個の結果が含まれている場合など
意外と使えます。

0daryo
webエンジニア Goが仕事 Javaかきます
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away