title: Taking a user's input string and splitting it in Java
body: <p>I want to take the input from a user, in this case, their full name and split it with the .split(" ") command into 2 or 3 sections, depending on number of names, and then print out the results on different lines:</p>
  
  <p>For example,</p>
  
  <p>User inputs: </p>
  
  <p>"John Doe Smith"</p>
  
  <p>Program returns:</p>
  
  <p>John</p>
  
  <p>Doe</p>
  
  <p>Smith</p>
  
  <p>Currently, my code looks like this:</p>
  
  <pre><code>import java.util.Scanner;
  public class Task2 {
      public static void main(String[] args) {
          Scanner input = new Scanner(System.in);
          String name;
          System.out.println("Enter your full name: ");
          name = input.next();
          String[] parts = name.split(" ");
          System.out.println(java.util.Arrays.toString(parts));
  
      }
  }
  </code></pre>
  
  <p>This currently only returns the first part of the name.</p>
  
  <p>The program should also be able to deal with someone not having a middle name.</p>