Sometimes, we need to change some special character on String to fulfill our requirements.
For example, we need to show phone number, i.e, 2001256443 as (200)-125-6443
Now we use the substring method of String to solve it.
We just add String on the particular location.
String phone = "2001256443";
String mobile = null;
mobile = "(" + phone.substring(0, 3) + ")" + phone.substring(3, 6) + "-" + phone.substring(6, phone.length());
System.out.println("Phone : "+mobile);
O/P:
Phone : (200)-125-6443
0 Comment(s)