赞
踩
【方法签名】<R> Stream<R> map(Function<? super T, ? extends R> mapper);
【方法属性】非终结方法
【方法参数】函数式接口 Function,所以可以直接传入一个Lambda表达式
【方法作用】将stream的元素进行处理,后返回一个新的stream
【方法返回值】 包含新元素的Stream对象
package com.northcastle.I_stream; import java.util.ArrayList; import java.util.stream.Stream; public class StreamTest07Map { public static void main(String[] args) { //1.准备一个List集合 ArrayList<String> list = new ArrayList<>(); list.add("1"); list.add("200"); list.add("300"); //2.获取Stream对象 Stream<String> streamList = list.stream(); //3.将元素映射为另一个元素 : 对字符串进行处理 streamList.map(s->"map"+s) .forEach(System.out::println); } }
Congratulations!
You are one step closer to success!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。