Stream API: last Stream element example refactor (#1943)
* Refactor * Delete ApplicationContextTestBeanInjectionTypes.java * Delete BeanInjectionJavaConfigIntegrationTest.java * Delete BeanInjectionXMLConfigIntegrationTest.java
This commit is contained in:
committed by
GitHub
parent
b840f15629
commit
a5d5460a9f
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user