Java tutorial
//package com.java2s; public class Main { public static String formatAccountNo(String accountNo) { try { StringBuffer s = new StringBuffer(); for (int i = 0; i < accountNo.length() - 10; i++) { s.append("*"); } StringBuffer sb = new StringBuffer(accountNo); sb.replace(6, accountNo.length() - 4, s.toString()); return sb.toString(); } catch (Exception e) { return accountNo; } } }