I want to transfer data generated by a method in a class to another method in another class. I assume this can be done with Streams
but I am not sure if this is the right way. Below is the pseudo code of what I am trying to achieve:
Class1.java
static Stream stream1;
getDataFromUpstream(List<SomeData> data){
Stream2 = Stream.of(data);
stream1.concat(stream2);
}
Class2.java
getData() {
Class1.stream1.forEach(data -> //do something);
}
If this can be achieved using streams, kindly suggest how. Otherwise, if there is any other way of streaming data like this in Java, please let me know.
I cannot call getData()
method from getDataFromUpstream()
directly.