title: Which is the best way to mask a String in Java?
body: <p>I want to apply a mask on a String "96506550" but I'm getting 965065-50 instead of 96506-550</p>
  
  <pre><code>//my method
  public String format(String data, String mask) {
          MaskFormatter mf = new MaskFormatter(mask);        
          return mf.valueToString(data);
  }
  
  System.out.println(formatter.format("96506550","#####-###"));
  </code></pre>