Java tutorial
//package com.java2s; //License from project: Apache License public class Main { public static String hideUsernameString(String username) { String clone = new String(username); char us[] = username.toCharArray(); if (username.length() > 5) { for (int i = 2; i < username.length() - 2; i++) { us[i] = '*'; clone = new String(us); } } else { for (int i = 1; i < username.length(); i++) { us[i] = '*'; clone = new String(us); } } return clone; } }