Collectors summingInt(ToIntFunction<? super T> mapper)
returns a Collector that produces the sum of a integer-valued
function applied to the input elements.
summingInt
has the following syntax.
public static <T> Collector<T,?,Integer> summingInt(ToIntFunction<? super T> mapper)
The following example shows how to use summingInt
.
import java.util.stream.Collectors; import java.util.stream.Stream; // w w w . j a va2 s.c o m public class Main { public static void main(String[] args) { Stream<String> s = Stream.of("1","2","3"); int o = s.collect(Collectors.summingInt(n->Integer.parseInt(n))); System.out.println(o); } }
The code above generates the following result.