Core Java 8 refactor (#3342)

This commit is contained in:
Grzegorz Piwowarek 2018-01-04 17:21:32 +02:00 committed by GitHub
parent 2afc7dc623
commit da4bd50cdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 4 deletions

View File

@ -1,4 +1,4 @@
package com.baeldung.streamApi;
package com.baeldung.stream;
import java.util.List;
import java.util.stream.Stream;

View File

@ -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);
}

View File

@ -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;

View File

@ -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);
}