Make use of MaskFormatter, for example...
MaskFormatter mf = new MaskFormatter("+# (###) ###-##-##");
mf.setValueContainsLiteralCharacters(false);
System.out.println(mf.valueToString("79991111111"));
which will output +7 (999) 111-11-11
Update
You should take a look at Googles libphonenumber - as formatting phone numbers does not have a simple solution
(ps - I've never used this before, this is all experimental on my part)
So, based on the documented examples, you could do something like...
// I had to add the `+` prefix, otherwise the parsing would fail
String input = "+79991111111";
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
try {
Phonenumber.PhoneNumber phoneNumber = phoneUtil.parse(input, CountryCodeSource.UNSPECIFIED.name());
System.out.println(phoneNumber);
System.out.println(phoneUtil.format(phoneNumber, PhoneNumberFormat.INTERNATIONAL));
System.out.println(phoneUtil.format(phoneNumber, PhoneNumberFormat.NATIONAL));
System.out.println(phoneUtil.format(phoneNumber, PhoneNumberFormat.E164));
} catch (NumberParseException e) {
System.err.println("NumberParseException was thrown: " + e.toString());
}
And this will print ...
+7 999 111-11-11
8 (999) 111-11-11
+79991111111
At this point you "should" be able to walk away, as these are using "standardised" formats, but, if you need to do something "special", you could make use of PhoneNumberUtil#formatByPattern, which might look something like...
String input = "+79991111111";
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
try {
NumberFormat newNumFormat = new NumberFormat();
newNumFormat.setPattern("(\\d{3})(\\d{3})(\\d{2})(\\d{2})");
newNumFormat.setFormat("($1) $2-$3-$4");
List<NumberFormat> newNumberFormats = new ArrayList<NumberFormat>();
newNumberFormats.add(newNumFormat);
String formatted = phoneUtil.formatByPattern(phoneNumber, PhoneNumberFormat.INTERNATIONAL, newNumberFormats);
System.out.println(formatted);
} catch (NumberParseException e) {
System.err.println("NumberParseException was thrown: " + e.toString());
}
and output something like...
+7 (999) 111-11-11
which, again, is probably as close as you will get.
Please also remember, formatting phone numbers is not simple as there are no real "standard" rules across all countries ... it's a mess