BAEL-583: Added test class for Java 8 findFirst() and findAny() example

This commit is contained in:
Stephen Braimah 2017-01-11 22:10:56 +00:00
parent 3116a73d24
commit 016d02ab17
1 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,37 @@
package com.baeldung.java8;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
public class Java8FindAnyFindFirstTest {
@Test
public void createStream_whenFindAnyResultIsPresent_thenCorrect() {
List<String> list = Arrays.asList("A","B","C","D");
Optional<String> result = list.stream().findAny();
if(result.isPresent()){
System.out.println(result.get());
}
}
@Test
public void createStream_whenFindFirstResultIsPresent_thenCorrect() {
List<String> list = Arrays.asList("A","B","C","D");
Optional<String> result = list.stream().findFirst();
if(result.isPresent()){
System.out.println(result.get());
}
}
}