title: How to find all special characters and print them in a given string?
body: <p>I need to find all special characters and even the spaces in a sting and print it as a out put..</p>
  
  <p>I have tried the following.</p>
  
  <pre><code>public class SpecialChar {
  
      public static void main(String[] args) {
  
          String s = "adad , dsd  r dsdsd,,,,..////";
  
          for (int i = 0; i &lt; s.length(); i++) 
          {
              System.out.println(s.charAt(i));
          }
  
          System.out.println("i");
  
  
          String REGEX = "[^&amp;%$#@!~ ,]*";
          Pattern pattern = Pattern.compile(REGEX);
  
          Matcher matcher = pattern.matcher(i);
          if (matcher.matches()) {
              System.out.println("matched");
          }
      }
  }
  </code></pre>