String fullname Split java
<p>I created a program which will parse the firstName, middleName and lastName. Here is the program and output. This program can definitely be improved and need some input on reducing my cumbersome ugly code and replace it with a better one. Any suggestions or example ? </p>

<pre><code>public class Test {

  public static void main(String[] args) {

    String fullName = "John King IV. Cena";
    String[] tokens = fullName.split(" ");
    String firstName = "";
    String middleName = "";
    String lastName = "";
    if(tokens.length &gt; 0) {
        firstName = tokens[0];
        middleName = tokens.length &gt; 2 ? getMiddleName(tokens) : "";
        lastName = tokens[tokens.length -1];
    }
    System.out.println(firstName);
    System.out.println(middleName);
    System.out.println(lastName);
  }

  public static String getMiddleName(String[] middleName){
      StringBuilder builder = new StringBuilder();
      for (int i = 1; i &lt; middleName.length-1; i++) {
          builder.append(middleName[i] + " ");
      }

      return builder.toString();
  }
}
</code></pre>

<p>John
King IV. 
Cena</p>
