title: How does RxJava Observable "Iteration" work?
body: <p>I started to play around with RxJava and ReactFX, and I became pretty fascinated with it. But as I'm experimenting I have dozens of questions and I'm constantly researching for answers. </p>
  
  <p>One thing I'm observing (no pun intended) is of course lazy execution. With my exploratory code below, I noticed nothing gets executed until the <code>merge.subscribe(pet -&gt; System.out.println(pet))</code> is called. But what fascinated me is when I subscribed a second subscriber <code>merge.subscribe(pet -&gt; System.out.println("Feed " + pet))</code>, it fired the "iteration" again. </p>
  
  <p>What I'm trying to understand is the behavior of the iteration. It does not seem to behave like a Java 8 <code>stream</code> that can only be used once. Is it literally going through each <code>String</code> one at a time and posting it as the value for that moment? And do any new subscribers following any previously fired subscribers receive those items as if they were new?</p>
  
  <pre><code>public class RxTest {
  
      public static void main(String[] args) {
  
          Observable&lt;String&gt; dogs = Observable.from(ImmutableList.of("Dasher", "Rex"))
                  .filter(dog -&gt; dog.matches("D.*"));
  
          Observable&lt;String&gt; cats = Observable.from(ImmutableList.of("Tabby", "Grumpy Cat", "Meowmers", "Peanut"));
  
          Observable&lt;String&gt; ferrets = Observable.from(CompletableFuture.supplyAsync(() -&gt; "Harvey"));
  
          Observable&lt;String&gt; merge = dogs.mergeWith(cats).mergeWith(ferrets);
  
          merge.subscribe(pet -&gt; System.out.println(pet));
  
  
          merge.subscribe(pet -&gt; System.out.println("Feed " + pet));
  
      }
  }
  </code></pre>