 <p>I would suggest you this approach:</p> <ul> <li>Split <code>userInput</code> string by white spaces: <code>userInput.split("\\s+")</code>. You will get an array. See <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split%28java.lang.String%29" rel="nofollow">String.split()</a></li> <li>For question 1: iterate over the array comparing each string with your <em>keyword</em>. See <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#equals%28java.lang.Object%29" rel="nofollow">String.equals()</a> and <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#equalsIgnoreCase%28java.lang.String%29" rel="nofollow">String.equalsIgnoreCase()</a>.</li> <li>For question 2: add the array to a <a href="http://docs.oracle.com/javase/6/docs/api/java/util/Set.html" rel="nofollow">Set</a>. As this can't contain any duplicate item, its size will give you the answer.</li> </ul>