title: Splitting a string into individual words (java)
body: <p>So I am trying to split a sentence into individual words and the code I am using is not working. I keep getting a null answer. After I break the sentence into words, I want to send each individual word to be converted to pig latin and then added to a string to form the original sentence but in pig latin.</p>
  
  <p>Here is the code I have:</p>
  
  <pre><code>public class PigLatin
  {
      String input;
      String pLatin = "";
  
      public PigLatin()
      {
         this.input = "Cool";
         this.pLatin = "Oolcay";
      }
  
      public PigLatin (String input)
      {
          this.input = input;
      }
  
      public void breakInput(String input)
      {
          String[] words = input.split("\\s");
          for(int i=0; i &lt; words.length; i++)
          {  
              System.out.println(words[i]);
              changeWord(words[i]);
          }
      }
  
      public void changeWord(String w)
      {
          char ch = w.charAt(0);
          String letter = ch+"";
          String beg = w.substring(1,w.length());
          String end = letter.concat("ay");
          String word = beg.concat(end);
  
          this.pLatin = pLatin.concat(" " + word);
          System.out.println(this.pLatin);
       }
  
      public String toString()
      {
          String ans = this.input + "\n" + this.pLatin;
          return ans;
      }
  }
  </code></pre>