title: String split with parseInt in Java
body: <p>We are asked to build a constructor for a Stopwatch that takes a string in the format of "##:##:###" and updates minutes, seconds and milliseconds (private instance variables) accordingly. For example, <code>"1:21:300"</code> indicates 1 minute 21 seconds 300 milliseconds.</p>
  
  <p>So I am trying to use <code>string.split()</code> paired with <code>parseInt</code> to update values. However, the program will not compile. My constructor has the correct syntax according to eclipse, but there is something wrong with what I am doing. I have never actually used <code>split</code> nor <code>parseInt</code>, so I could be using these 100% wrong. Thank you.</p>
  
  <pre><code>    public StopWatch(String startTime){
      String [] timeArray = startTime.split(":");
  
      if(timeArray.length == 2){
          this.minutes = Integer.parseInt(timeArray[0]);
          this.seconds = Integer.parseInt(timeArray[1]);
          this.milliseconds = Integer.parseInt(timeArray[2]);
      }
      else if(timeArray.length == 1){
          this.minutes =  0;
          this.seconds = Integer.parseInt(timeArray[1]);
          this.milliseconds =    Integer.parseInt(timeArray[2]);              
      }
      else if(timeArray.length == 0){
          this.minutes = 0;
          this.seconds = 0;
          this.milliseconds = Integer.parseInt(timeArray[2]);             
      }
      else{
          this.minutes = 0;
          this.seconds = 0;
          this.milliseconds = 0;
      }
  }
  </code></pre>
  
  <p>P.S. Junit test says "ComparisonFailue: expected 0:00:000 but was 20:10:008" when trying to do:</p>
  
  <pre><code>s = new StopWatch("20:10:8");
  assertEquals(s.toString(),"20:10:008");
  </code></pre>