You can use String.replaceFirst with regex method like
long phoneNum = 123456789L;
System.out.println(String.valueOf(phoneNum).replaceFirst("(\\d{3})(\\d{3})(\\d+)", "($1)-$2-$3"));
More Related Contents:
- Convert float to String and String to float in Java
- How can I format a String number to have commas and round?
- Regex for converting xml tags key to camel case
- Remove duplicate phrases [closed]
- How to split a string with any whitespace chars as delimiters
- What is meant by immutable?
- What is the purpose of the expression “new String(…)” in Java?
- A quick and easy way to join array elements with a separator (the opposite of split) in Java [duplicate]
- How does the String class override the + operator?
- How to format strings in Java
- How to convert Strings to and from UTF8 byte arrays in Java
- Left padding a String with Zeros [duplicate]
- How to find nth occurrence of character in a string?
- Using Java to find substring of a bigger string using Regular Expression
- How to use java.String.format in Scala?
- How is String concatenation implemented in Java 9?
- Reversing a String with Recursion in Java
- Remove trailing zero in Java
- How do I split a string in Java?
- How can I remove a substring from a given String?
- Trim characters in Java
- Printing reverse of any String without using any predefined function?
- Java split string to array [duplicate]
- In Java, for a string x, what is the runtime cost of s.length()? Is it O(1) or O(n)?
- Preferred Idiom for Joining a Collection of Strings in Java
- How can I parse a String to BigDecimal? [duplicate]
- Verify if String is hexadecimal
- Is there a memory-efficient replacement of java.lang.String?
- String equals and == with String concatenation [duplicate]
- Java printf using variable field size?