一、获取Stream流
import java.util.*;
public class StreamDemo02 {
public static void main(String[] args) {
Collection<String> list = new ArrayList<>();
Stream<String> s = list.stream();
Map<String, Integer> maps = new HashMap<>();
Stream<String> keyStream = maps.keySet().stream();
Stream<Integer> valueStream = maps.values().stream();
Stream<Map.Entry<String,Integer>> keyAndValueStream = maps.entrySet().stream();
String[] names = {"赵敏","小昭","灭绝","周芷若"};
Stream<String> nameStream = Arrays.stream(names);
Stream<String> nameStream2 = Stream.of(names);
}
}
二、Stream流常用API
Stream<T> sorted(Comparator<? super T> comparator)
Stream<T> limit(long maxSize)
void forEach(Consumer<? super T> action)
Stream<T> filter(Predicate<? super T> predicate)
long count()
Stream<T> skip(long n)
<R> Stream<R> map(Function<? super T,? extends R> mapper)
static <T> Stream<T> concat(Stream<? extends T> a, Stream<? extends T> b)