title: How to filter a string to only include characters that are allowed?
body: <p>I am trying to filter a string to only contain characters that I allow. For example let's say I allow letters [A-Z] (case insensitive) and underscores ('_').</p>
  <p>So let's say I have the string:
  <code>&quot;I am a happy_bear and I sk@8 because it's gr8&quot;</code></p>
  <p>I would want it to be filtered to:
  <code>&quot;I am a happy_bear and I sk because its gr&quot;</code></p>
  <p>What I have tried so far:</p>
  <pre class="lang-java prettyprint-override"><code>//Define a method to check allowed charachters
   private boolean checkAllowed(Character ch) {
          return Character.isLetter(ch) || ch == '_';
      }
  </code></pre>
  <pre class="lang-java prettyprint-override"><code>// loop through string
  for (int i = 0; i &lt; someString.length(); i++) {
              if (this.checkAllowed(someString.charAt(i)) {
                  // append to a list
              }
          }
  </code></pre>
  <p>How can I filter a string to only include characters that I allow? Is that achievable with a stream-like filtering? Can this be done easier without regex? (I am looking for a better way to do this)</p>