Return from lambda forEach() in java

后端 未结 5 574
不知归路
不知归路 2020-12-13 02:14

I am trying to change some for-each loops to lambda forEach()-methods to discover the possibilities of lambda expressions. The following seems to be possible:

5条回答
  •  温柔的废话
    2020-12-13 02:28

    This what helped me:

    List fileList = response.getRepositoryFileList();
    RepositoryFile file1 = fileList.stream().filter(f -> f.getName().contains("my-file.txt")).findFirst().orElse(null);
    

    Taken from Java 8 Finding Specific Element in List with Lambda

提交回复
热议问题