BAEL-1330 Primitive Type Streams in Java 8 (#3106)
* initial commit for first article evaluation * fixed compilation error * removed final keywords for compliance * added unit tests and refactored as needed * refactored application-context.xml to use self-closing tags * renamed tests to use UnitTest suffix * removed unnecessary annotation * added code samples for primitive streams * removed sample code and tests for evaluation article * renamed unit test to proper unit test naming * added a test to show boxed method * added the assertion to the test fox boxed * changed mapToInt test to use Arrays.asList instead of a POJO as per Grzegorz and Eugen
This commit is contained in:
committed by
Grzegorz Piwowarek
parent
171d28a9d1
commit
ae109dfb7c
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.stream;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
class PrimitiveStreams {
|
||||
|
||||
int min(int[] integers) {
|
||||
return Arrays.stream(integers).min().getAsInt();
|
||||
}
|
||||
|
||||
int max(int... integers) {
|
||||
return IntStream.of(integers).max().getAsInt();
|
||||
}
|
||||
|
||||
int sum(int... integers) {
|
||||
return IntStream.of(integers).sum();
|
||||
}
|
||||
|
||||
double avg(int... integers) {
|
||||
return IntStream.of(integers).average().getAsDouble();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user