回到首页
个人中心
反馈问题
注册登录
下载APP
代码
提交代码
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Stream; public class Test{ public static void main(String...s){ List<Integer> numbers = new ArrayList<Integer>(); Collections.addAll(numbers,new Integer[]{1,2,3,4,5,6,7}); Stream stream1 = numbers.stream(); numbers.remove(6); //直接使用numbers的stream() long counter = numbers.stream().filter(e->e>5).count(); System.out.println(counter); //调用之前的stream1 counter = stream1.filter(ex-> (Integer)ex>5).count(); System.out.println(counter); } }
运行结果