Skip to content

Commit d737987

Browse files
authored
Proposing different approach to sum numbers
- Updated MediumNumbersProblemSolution.java There is a boxing cost while doing arithmetic operations on Wrapper types. Although it wouldn't make much difference for this learning exercise but just wanted to propose this small change as many new developers will read this guide.
1 parent ef665be commit d737987

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/test/java/com/github/streams/practice/b_medium/numbers/MediumNumbersProblemSolution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static <T> List<T> getUniqueNumberFromList(List<T> input) {
3838
}
3939

4040
public static long sumOfNumbers(List<Integer> input) {
41-
return input.stream().reduce(0, Integer::sum);
41+
return input.stream().mapToInt(Integer::intValue).sum();
4242
}
4343

4444
public static long sumOfUniqueNumbers(List<Integer> input) {

0 commit comments

Comments
 (0)