代码
提交代码
import java.util.List; import java.util.ArrayList; import java.util.Collections; import java.util.stream.Collectors; public class Test{ public static void main(String...s) { List<Integer> numbers = new ArrayList<>(); Collections.addAll(numbers,new Integer[]{1,2,3,4,5,6,7}); List<Integer> collected = numbers.stream() .filter(e->e>5).collect(Collectors.toList()); System.out.println(collected); } }
运行结果