LoginSignup
0
0

More than 5 years have passed since last update.

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

Last updated at Posted at 2018-10-06

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

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

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

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

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