Here you can find the source of formata(String s, String mascara)
public static String formata(String s, String mascara)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import javax.swing.text.MaskFormatter; public class Main { public static String formata(String s, String mascara) { MaskFormatter formatter;// w ww . jav a 2s .c o m try { formatter = new MaskFormatter(mascara); formatter.setValueContainsLiteralCharacters(false); return formatter.valueToString(s); } catch (ParseException e) { return s; } } }