package com.shrimpking.t3;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;
/**
* Created by IntelliJ IDEA.
*
* @Author : Shrimpking
* @create 2024/9/11 14:25
*/
public class CreateStream
{
public static void main(String[] args)
{
List<Integer> list = Arrays.asList(1,3,5,7,9);
//从集合创建流
Stream<Integer> stream1 = list.stream();
stream1.forEach(x -> System.out.printf("%d ",x));
System.out.println();
int[] intArr = new int[]{2,4,6,8,10};
//从数据创建流
IntStream stream2 = Arrays.stream(intArr);
stream2.forEach(x -> System.out.printf("%d ",x));
System.out.println();
//由值创建流
Stream<String> stream3 = Stream.of("one","two","three");
stream3.forEach(x -> System.out.printf("%s ",x));
System.out.println();
//创建无限流
Stream<Integer> stream4 = Stream.iterate(0,x -> x + 2);
stream4.limit(5).forEach(x -> System.out.printf("%d ",x));
System.out.println();
//生成随机数无限流
Stream<Double> stream6 = Stream.generate(()-> Math.random());
stream6.limit(5).forEach(x -> System.out.printf("%f ",x));
System.out.println();
//从1到5,创建整数流
IntStream stream7 = IntStream.range(1,5);
stream7.forEach(x-> System.out.printf("%d ",x));
System.out.println();
//从1到5 创建浮点数流
LongStream stream8 = LongStream.rangeClosed(1,5);
stream8.forEach(x -> System.out.printf("%d ",x));
System.out.println();
}
}
CreateStream
原创
©著作权归作者所有:来自51CTO博客作者虾米大王的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:PartialStream
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Kafka + spark stream +redis (createStream + createDirectStream)
我们的应用场景是分析用户使用手机App的行为,描述如下所示:1、手机客户端会收集用户的行为事件(我们以点击事件为
spark redis scala zookeeper 实例 -
KafkaUtils.createStream接收数据流程
KafkaUtils.createStream接收数据流程
资料分享 微信公众号 大数据 -
spark写入kafka认证 spark读kafka
sparkstreaming 消费kafka数据的 kafkautil 提供两种创建dstream的方法: 1 老版本的createStream方法 &
spark写入kafka认证 kafka 分布式 数据 偏移量