I tried to mask the characters in a creditcard number string using character \'X\'.I wrote two functions as below .The second function uses commons.lang.StringUtils
commons.lang.StringUtils
Using Apache StringUtils...
String ccNumber = "123232323767"; StringUtils.overlay(ccNumber, StringUtils.repeat("X", ccNumber.length()-4), 0, ccNumber.length()-4);