Example for intersperse (#28343)

This commit is contained in:
Christopher Batey 2019-12-11 14:39:41 +00:00 committed by Johan Andrén
parent 1e67d9221e
commit 17533f077c
4 changed files with 70 additions and 9 deletions

View file

@ -0,0 +1,25 @@
/*
* Copyright (C) 2019 Lightbend Inc. <https://www.lightbend.com>
*/
package jdocs.stream.operators.sourceorflow;
import akka.actor.ActorSystem;
import akka.stream.javadsl.Source;
import java.util.Arrays;
public class Intersperse {
public static void main(String[] args) {
ActorSystem system = ActorSystem.create();
// #intersperse
Source.from(Arrays.asList(1, 2, 3))
.map(String::valueOf)
.intersperse("[", ", ", "]")
.runForeach(System.out::print, system);
// prints
// [1, 2, 3]
// #intersperse
system.terminate();
}
}