title: Java - Splitting string by backslash (\)
body: <p>I'm trying to split a string by a backslash but I'm having problems. I'm sure I have the expression right can someone read what I've done and tell me my problem?</p>
  
  <hr>
  
  <pre><code>package taskstodo;
  
  public class Task {
      StringBuilder name;
      StringBuilder note;
      StringBuilder date;
  
      void setName(String name) {
          this.name = new StringBuilder(name);
      }
      void setNote(String note) {
          this.note = new StringBuilder(note);
      }
      boolean dateIsValid() {
          String dateStr = date.toString();
          String[] numbers = (dateStr.split("[\\\\]"));
          for(String num : numbers) {
              System.out.println(num);
              if ((num.length()) != 2) {
                  return false;
              }
              return true;
          }
          return true;
      }
      void setDate(String date) {
          this.date = new StringBuilder(date);
      }
  }
  </code></pre>
  
  <hr>
  
  <p>package taskstodo;</p>
  
  <p>public class TasksToDo {</p>
  
  <pre><code>public static void main(String[] args) {
      Task myTask = new Task();
      myTask.setDate("02/03/20");
      System.out.println(myTask.dateIsValid());
      Task myTask2 = new Task();
      myTask2.setDate("23/45/6001");
      System.out.println(myTask2.dateIsValid());
  }
  </code></pre>
  
  <p>}</p>
  
  <hr>
  
  <p>The TasksToDo class tests the Task class.</p>
  
  <p>It should return:</p>
  
  <pre><code>02
  03
  20
  true
  23
  45
  6001
  false
  </code></pre>
  
  <p>But it returns:</p>
  
  <pre><code>02/03/20
  false
  23/45/6001
  false
  </code></pre>