title: Splitting a Java String by the pipe symbol using split("|")
body: <p>The Java official documentation states:</p>
  
  <p>The string <code>"boo:and:foo"</code>, for example, yields the following results with these expressions 
  Regex   Result
  :   </p>
  
  <pre><code>{ "boo", "and", "foo" }"
  </code></pre>
  
  <p>And that's the way I need it to work. However, if I run this:</p>
  
  <pre><code>public static void main(String[] args){
          String test = "A|B|C||D";
  
          String[] result = test.split("|");
  
          for(String s : result){
              System.out.println("&gt;"+s+"&lt;");
          }
      }
  </code></pre>
  
  <p>it prints:</p>
  
  <pre><code>&gt;&lt;
  &gt;A&lt;
  &gt;|&lt;
  &gt;B&lt;
  &gt;|&lt;
  &gt;C&lt;
  &gt;|&lt;
  &gt;|&lt;
  &gt;D&lt;
  </code></pre>
  
  <p>Which is far from what I would expect:</p>
  
  <pre><code>&gt;A&lt;
  &gt;B&lt;
  &gt;C&lt;
  &gt;&lt;
  &gt;D&lt;
  </code></pre>
  
  <p>Why is this happening?</p>