title: Difference between Flux.concat and Flux.concatWith
body: <p>I am new to reactive streams and learning the combine two publishers (Flux to be specific) using the concat/concatWith methods.</p>
  
  <p>Everything which i can do with concat method, the same can be achieved using the concatWith method. Here is the sample cases which i used:</p>
  
  <pre><code>        Mono&lt;String&gt; mono1 = Mono.just(" karan ");
          Mono&lt;String&gt; mono2 = Mono.just(" | verma ");
          Mono&lt;String&gt; mono3 = Mono.just(" | kv ");
  
          Flux&lt;String&gt; flux1 = Flux.just(" {1} ","{2} ","{3} ","{4} " );
          Flux&lt;String&gt; flux2 = Flux.just(" |A|"," |B| "," |C| ");
  
          // FLux emits item each 500ms
          Flux&lt;String&gt; intervalFlux1 = Flux.interval(Duration.ofMillis(1000))
                                          .zipWith(flux1, (i, string) -&gt; string);
  
          // FLux emits item each 700ms       
          Flux&lt;String&gt; intervalFlux2 = Flux
                                  .interval(Duration.ofMillis(1000))
                                  .zipWith(flux2, (i, string) -&gt; string);
  
  
  
          System.out.println("**************Flux Concat***************");
          Flux.concat(mono1, mono2, mono3).subscribe(System.out::print);
          System.out.println();
          Flux.concat(flux2, flux1).subscribe(System.out::print);
          System.out.println();
          Flux.concat(intervalFlux2, flux1).subscribe(System.out::print);
  
          Thread.sleep(5000);
  
          System.out.println();
          Flux.concat(intervalFlux2, intervalFlux1).subscribe(System.out::print);
          Thread.sleep(10000);
          System.out.println("----------------------------------------");
  
  
          System.out.println("**************Flux Concat with***************");
          mono1.concatWith(mono2).concatWith(mono3).subscribe(System.out::print);
          System.out.println();
          flux1.concatWith(flux2).subscribe(System.out::print);
  
          System.out.println();
          intervalFlux1.concatWith(flux2).subscribe(System.out::print);
          Thread.sleep(5000);
  
          System.out.println();
          intervalFlux1.concatWith(intervalFlux2).subscribe(System.out::print);
          Thread.sleep(10000);
          System.out.println();
  
          System.out.println("----------------------------------------");
  </code></pre>
  
  <p>and here is the output for both the cases:</p>
  
  <pre><code>**************Flux Concat***************
   karan  | verma  | kv 
   |A| |B|  |C|  {1} {2} {3} {4} 
   |A| |B|  |C|  {1} {2} {3} {4} 
   |A| |B|  |C|  {1} {2} {3} {4} ----------------------------------------
  **************Flux Concat with***************
   karan  | verma  | kv 
   {1} {2} {3} {4}  |A| |B|  |C| 
   {1} {2} {3} {4}  |A| |B|  |C| 
   {1} {2} {3} {4}  |A| |B|  |C| 
  ----------------------------------------
  </code></pre>
  
  <p>and the time complexity was also similar for both cases.</p>
  
  <p>What is the difference between the two?
  Is there any specific conditions, when concat or concatWith should be used? </p>