You can do
int sum = lst.stream().filter(o -> o.getField() > 10).mapToInt(o -> o.getField()).sum();
or (using Method reference)
int sum = lst.stream().filter(o -> o.getField() > 10).mapToInt(Obj::getField).sum();
More Related Contents:
- Get List<K> from HashMap<K, V> where V is instance of I [closed]
- Java 8 Streams: multiple filters vs. complex condition
- Java 8 Distinct by property
- In Java streams is peek really only for debugging?
- Why filter() after flatMap() is “not completely” lazy in Java streams?
- How to force max to return ALL maximum values in a Java Stream?
- Copy a stream to avoid “stream has already been operated upon or closed”
- Java 8 Nested (Multi level) group by
- Should I return a Collection or a Stream?
- What is difference between Collection.stream().forEach() and Collection.forEach()?
- Find first element by predicate
- Why is a combiner needed for reduce method that converts type in java 8
- Filter Java Stream to 1 and only 1 element
- Find maximum, minimum, sum and average of a list in Java 8
- Does Java SE 8 have Pairs or Tuples?
- Does Stream.forEach respect the encounter order of sequential streams?
- Most efficient way to get the last element of a stream
- Why does findFirst() throw a NullPointerException if the first element it finds is null?
- Java streams lazy vs fusion vs short-circuiting
- Collectors.summingInt() vs mapToInt().sum()
- Java 8 Stream IllegalStateException: Stream has already been operated on or closed
- How to check if a Java 8 Stream is empty?
- Stream Way to get index of first element matching boolean
- How to sum values in a Map with a stream?
- Is mapToDouble() really necessary for summing a List with Java 8 streams?
- Is it possible to cast a Stream in Java 8?
- Adding two Java 8 streams, or an extra element to a stream
- Visualization of Java Stream parallelization
- Get last element of Stream/List in a one-liner
- Java Stream API – count items of a nested list