391 Stream流中间操作之map&mapToInt
(复杂的课)
| | 返回经过指定操作的流,Function接口中的方法R apply(T t) |
| intStream mapToInt(ToIntFunction mapper) | 返回一个经过指定操作的IntStream流, intStream:原始int流 ToIntFunction:函数式接口,接口中的方法int applyAsInt(T value)根据T类型的参数得到int数据 |
intStream是接口,是原始的int值的序列,有一个sum方法,对其所包含的元素求和
---------------------------------------------
package e385aso;
import java.util.ArrayList;
public class Demo391MapToInt {
public static void main(String[] args) {
ArrayList
al391.add("10");
al391.add("20");
al391.add("30");
al391.add("40");
al391.add("50");
al391.stream().map(s->Integer.parseInt(s)).forEach(System.out::print);
System.out.println();
int result = al391.stream().mapToInt(Integer::parseInt).sum();
System.out.println(result);
}
}
//1020304050
//150



