BAEL-583: Added test class for Java 8 findFirst() and findAny() example
This commit is contained in:
parent
3116a73d24
commit
016d02ab17
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue