Core Java 8 refactor (#3342)
This commit is contained in:
parent
2afc7dc623
commit
da4bd50cdb
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.streamApi;
|
||||
package com.baeldung.stream;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
|
@ -16,7 +16,7 @@ public class StreamApi {
|
|||
}
|
||||
|
||||
public static String getLastElementUsingSkip(List<String> valueList) {
|
||||
long count = valueList.stream().count();
|
||||
long count = (long) valueList.size();
|
||||
Stream<String> stream = valueList.stream();
|
||||
return stream.skip(count - 1).findFirst().orElse(null);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.baeldung.java8;
|
||||
|
||||
import com.baeldung.streamApi.Product;
|
||||
import com.baeldung.stream.Product;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -65,7 +66,9 @@ public class PrimitiveStreamsUnitTest {
|
|||
@Test
|
||||
public void givenAnArrayWhenSumIsCalledThenTheCorrectSumIsReturned() {
|
||||
|
||||
int sum = Arrays.asList(33,45).stream().mapToInt(a -> a).sum();
|
||||
int sum = Stream.of(33,45)
|
||||
.mapToInt(i -> i)
|
||||
.sum();
|
||||
|
||||
assertEquals(78, sum);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue