[AIGC] Flink入门教程:理解DataStream API(Java版)-创建DataStream

时间:2024-03-09 13:29:35

要创建一个DataStream,我们需要从一个Source开始,例如,一个集合或一个文件。下面是一个简单的例子说明如何从一个集合创建一个DataStream:

final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

DataStream<String> text = env.fromElements(
    "To be, or not to be,--that is the question:--",
    "Whether 'tis nobler in the mind to suffer",
    "The slings and arrows of outrageous fortune"
);