Stream API: last Stream element example refactor (#1943)

* Refactor

* Delete ApplicationContextTestBeanInjectionTypes.java

* Delete BeanInjectionJavaConfigIntegrationTest.java

* Delete BeanInjectionXMLConfigIntegrationTest.java
This commit is contained in:
Grzegorz Piwowarek
2017-06-03 20:49:56 +02:00
committed by GitHub
parent b840f15629
commit a5d5460a9f
22 changed files with 11 additions and 531 deletions

View File

@@ -5,17 +5,17 @@ import java.util.stream.Stream;
public class StreamApi {
public String getLastElementUsingReduce(List<String> valueList) {
public static String getLastElementUsingReduce(List<String> valueList) {
Stream<String> stream = valueList.stream();
return stream.reduce((first, second) -> second).orElse(null);
}
public Integer getInfiniteStreamLastElementUsingReduce() {
public static Integer getInfiniteStreamLastElementUsingReduce() {
Stream<Integer> stream = Stream.iterate(0, i -> i + 1);
return stream.limit(20).reduce((first, second) -> second).orElse(null);
}
public String getLastElementUsingSkip(List<String> valueList) {
public static String getLastElementUsingSkip(List<String> valueList) {
long count = valueList.stream().count();
Stream<String> stream = valueList.stream();
return stream.skip(count - 1).findFirst().orElse(null);