title: Change order of words Java
body: <p>I cannot figure out how to change the order of a given name. </p>
  
  <p>For example: Van-Dame Claud 
  Result: Claud Dame-Van</p>
  
  <p>I created this method, but it seems that is not correct, any suggestion or maybe a better method?</p>
  
  <pre><code>  public String NameInvers(){
  String Name, Name = null, Name = null, NameFinal;
      int s1 = getName().indexOf(' ');
      int s2 = getName().indexOf('-');
      if(s1 != 0){
         Name1 = getName().substring(0, s1);
      if(s2 != 0)
      {
      Name2 = getName().substring(s1, s2);
      Name3 = getName().substring(s2);
      }
      NameFinal = Name3 + Name2 + Name1;
      }
      else
          NameFinal = getName();
  
      return NameFinal;
    }
  </code></pre>
  
  <p>Edit: In my Main method I have a number of names. The thing is that it says: throw new StringIndexOutOfBoundsException(subLen) and it won't show up. </p>