Skip to content

Instantly share code, notes, and snippets.



Created Jan 19, 2021
What would you like to do?
import; import; import; import; import java.util.List; import; import;
public class Main {
private static String filename = "fib1000";
static Stream<Long> fibonacciStream() {
return Stream.iterate(new long[]{1, 0}, (f) -> new long[]{f[0] + f[1], f[0]}).map(f -> f[0]);
public static void main(String[] args) throws Exception {
List<Long> fib1000 = fibonacciStream().limit(1000).collect(Collectors.toList());
try (ObjectOutputStream oss = new ObjectOutputStream(new FileOutputStream(filename))) {
Object deserializedFib1000;
try (ObjectInputStream oss = new ObjectInputStream(new FileInputStream(filename))) {
deserializedFib1000 = oss.readObject();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment