title: How to split a String into a Stream of Strings?
body: <p>What is the <strong>best</strong> method of splitting a String into a Stream?</p>
  
  <p>I saw these variations:</p>
  
  <ol>
  <li><code>Arrays.stream("b,l,a".split(","))</code></li>
  <li><code>Stream.of("b,l,a".split(","))</code></li>
  <li><code>Pattern.compile(",").splitAsStream("b,l,a")</code></li>
  </ol>
  
  <p>My priorities are:</p>
  
  <ul>
  <li>Robustness</li>
  <li>Readability</li>
  <li>Performance</li>
  </ul>
  
  <p>A complete, compilable <a href="http://www.tutorialspoint.com/compile_java8_online.php?PID=0Bw_CjBb95KQMYnF0LVNvSnJrUnM" rel="noreferrer">example</a>:</p>
  
  <pre><code>import java.util.Arrays;
  import java.util.regex.Pattern;
  import java.util.stream.Stream;
  
  public class HelloWorld {
  
      public static void main(String[] args) {
          stream1().forEach(System.out::println);
          stream2().forEach(System.out::println);
          stream3().forEach(System.out::println);
      }
  
      private static Stream&lt;String&gt; stream1() {
          return Arrays.stream("b,l,a".split(","));
      }
  
      private static Stream&lt;String&gt; stream2() {
          return Stream.of("b,l,a".split(","));
      }
  
      private static Stream&lt;String&gt; stream3() {
          return Pattern.compile(",").splitAsStream("b,l,a");
      }
  
  }
  </code></pre>