package Stream ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Map ; import java . util . stream . Collectors ; import java . util . stream . Stream ; /** * @Author yqq
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @Author yqq
* @Date 2021/10/17 01:12
* @Version 1.0
*/
public class DataSource {
public static void main(String[] args) {
collectionDataSource();
}
public static void collectionDataSource(){
//1,实例化一个集合
List<Integer> list = new ArrayList<>();
//2,填充元素
Collections.addAll(list,0,1,2,3,4,5,6,7,8,9);
//3,读取集合中的数据,将其读取到流中
Stream<Integer> stream = list.stream();
System.out.println(stream);
Map<String,Integer> collect = stream.collect(Collectors.toMap(i ->i.toString(), i -> i));
System.out.println(collect);
}
}