title: Java splitting input
body: <p>i'm trying to write a simple code for my project
  if user types </p>
  
  <blockquote>
    <p>walk 10</p>
  </blockquote>
  
  <p>i need to use "walk" command in my walk(distance) method as distance = 10
  i have something like that </p>
  
  <pre><code>while (!quit) {
  Scanner in = new Scanner(System.in);
  String input = in.nextLine();
  // if (walk x is typed) {
  walk(x);
  }
  }
  </code></pre>
  
  <p>i'm using java.util.scanner
  and another problem is that my method walk(int x) uses int
  so i need to convert String input to int  </p>
  
  <p>i searched the web for a while but couldnt find what i'm looking for (or i didnt understand it)</p>
  
  <p>so anyway i'd appreciate if you can help me thanks</p>
  
  <p><strong>Thanks a lot for all the answers my initial problem is fixed
  but now i have another problem</strong>
  when i type just "walk" it gets array out of bounds exception
  of course because it tries to convert null to an int (not possible) 
  i tried this and checked online</p>
  
  <pre><code>                    try {
                      Integer.parseInt(splitStrings[1]);
                      }
                      catch(NumberFormatException e) {
                      System.out.println("error: " + e);
                      }
  </code></pre>
  
  <p>still no help (i'm not good with try/catches)
  so if user types walk without a distance i need to give an error message
  thanks a lot again</p>
  
  <p>ok i got it too
  just used a simple thing</p>
  
  <pre><code>            if ("walk".equals(splitStrings[0])) {
                  if (splitStrings.length == 2) {
                  int distance = Integer.parseInt(splitStrings[1]);
                  Robot.walk(distance);
                  }
                  if (splitStrings.length != 2) {
                      System.out.println("Entry must be like walk 10");
                  }
              }
  </code></pre>