 <p><code>Pattern.matches</code> would try to match the pattern exactly..</p> <p>So it would return <code>true</code> only if you have a <strong>single</strong> non space character as input.</p> <p>Its like using <code>\A[^ ]\z</code></p> <p>where <code>\A</code> is the beginning of input and <code>\z</code> is end of input..</p> <hr> <p>If you want to check for strings that doesn't contain space you can use</p> <pre><code>input.matches("[^ ]*"); </code></pre>